我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用pandas.reset_option()。
def test_wide_repr(self): with option_context('mode.sim_interactive', True, 'display.show_dimensions', True): max_cols = get_option('display.max_columns') df = DataFrame(tm.rands_array(25, size=(10, max_cols - 1))) set_option('display.expand_frame_repr', False) rep_str = repr(df) assert "10 rows x %d columns" % (max_cols - 1) in rep_str set_option('display.expand_frame_repr', True) wide_repr = repr(df) self.assertNotEqual(rep_str, wide_repr) with option_context('display.width', 120): wider_repr = repr(df) self.assertTrue(len(wider_repr) < len(wide_repr)) reset_option('display.expand_frame_repr')
def test_wide_repr_named(self): with option_context('mode.sim_interactive', True): max_cols = get_option('display.max_columns') df = DataFrame(tm.rands_array(25, size=(10, max_cols - 1))) df.index.name = 'DataFrame Index' set_option('display.expand_frame_repr', False) rep_str = repr(df) set_option('display.expand_frame_repr', True) wide_repr = repr(df) self.assertNotEqual(rep_str, wide_repr) with option_context('display.width', 150): wider_repr = repr(df) self.assertTrue(len(wider_repr) < len(wide_repr)) for line in wide_repr.splitlines()[1::13]: self.assertIn('DataFrame Index', line) reset_option('display.expand_frame_repr')
def test_wide_repr_multiindex(self): with option_context('mode.sim_interactive', True): midx = MultiIndex.from_arrays(tm.rands_array(5, size=(2, 10))) max_cols = get_option('display.max_columns') df = DataFrame(tm.rands_array(25, size=(10, max_cols - 1)), index=midx) df.index.names = ['Level 0', 'Level 1'] set_option('display.expand_frame_repr', False) rep_str = repr(df) set_option('display.expand_frame_repr', True) wide_repr = repr(df) self.assertNotEqual(rep_str, wide_repr) with option_context('display.width', 150): wider_repr = repr(df) self.assertTrue(len(wider_repr) < len(wide_repr)) for line in wide_repr.splitlines()[1::13]: self.assertIn('Level 0 Level 1', line) reset_option('display.expand_frame_repr')
def test_wide_repr_multiindex_cols(self): with option_context('mode.sim_interactive', True): max_cols = get_option('display.max_columns') midx = MultiIndex.from_arrays(tm.rands_array(5, size=(2, 10))) mcols = MultiIndex.from_arrays(tm.rands_array(3, size=(2, max_cols - 1))) df = DataFrame(tm.rands_array(25, (10, max_cols - 1)), index=midx, columns=mcols) df.index.names = ['Level 0', 'Level 1'] set_option('display.expand_frame_repr', False) rep_str = repr(df) set_option('display.expand_frame_repr', True) wide_repr = repr(df) self.assertNotEqual(rep_str, wide_repr) with option_context('display.width', 150): wider_repr = repr(df) self.assertTrue(len(wider_repr) < len(wide_repr)) reset_option('display.expand_frame_repr')
def get_turbine_types(print_out=True, **kwargs): r""" Get the names of all possible wind turbine types for which the power coefficient curve or power curve is provided in the data files in the directory windpowerlib/data. Parameters ---------- print_out : boolean Directly prints the list of types if set to True. Default: True. Examples -------- >>> from windpowerlib import wind_turbine >>> turbines = wind_turbine.get_turbine_types(print_out=False) >>> print(turbines[turbines["turbine_id"].str.contains("ENERCON")].iloc[0]) turbine_id ENERCON E 101 3000 p_nom 3000000 Name: 25, dtype: object """ df = read_turbine_data(**kwargs) if print_out: pd.set_option('display.max_rows', len(df)) print(df[['turbine_id', 'p_nom']]) pd.reset_option('display.max_rows') return df[['turbine_id', 'p_nom']]
def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) pd.reset_option("display.chop_threshold") # default None self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1') with option_context("display.chop_threshold", 0.2): self.assertEqual(repr(df), ' 0 1\n0 0.0 0.5\n1 0.5 0.0') with option_context("display.chop_threshold", 0.6): self.assertEqual(repr(df), ' 0 1\n0 0.0 0.0\n1 0.0 0.0') with option_context("display.chop_threshold", None): self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1')
def reset_display_options(self): # reset the display options pd.reset_option('^display.', silent=True)
def print_full(x): """Print all rows in Pandas DataFrame x.""" pd.set_option('display.max_rows', len(x)) print(x) pd.reset_option('display.max_rows')
def print_full(df): ''' print all rows of pd.DataFrame ''' pd.set_option('display.max_rows', len(df)) print('\n') print(df) pd.reset_option('display.max_rows') # TODO:
def print_full(x): pd.set_option('display.max_rows', len(x)) print(x) pd.reset_option('display.max_rows')