Python pandas 模块,reset_option() 实例源码
我们从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', 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', 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, 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', 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, 10)))
mcols = MultiIndex.from_arrays(tm.rands_array(3, max_cols
- 1)))
df = DataFrame(tm.rands_array(25, (10,
index=midx, columns=mcols)
df.index.names = ['Level 0', 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')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。