本文整理汇总了Python中pandas.get_option方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.get_option方法的具体用法?Python pandas.get_option怎么用?Python pandas.get_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.get_option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _repr_html_
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def _repr_html_(self):
if len(self._executed_sessions) == 0:
# not executed before, fall back to normal repr
raise NotImplementedError
corner_data = fetch_corner_data(
self, session=self._executed_sessions[-1])
buf = StringIO()
max_rows = pd.get_option('display.max_rows')
if self.shape[0] <= max_rows:
buf.write(corner_data._repr_html_())
else:
with pd.option_context('display.show_dimensions', False,
'display.max_rows', corner_data.shape[0] - 1):
buf.write(corner_data._repr_html_().rstrip().rstrip('</div>'))
if pd.get_option('display.show_dimensions'):
n_rows, n_cols = self.shape
buf.write(
"<p>{nrows} rows × {ncols} columns</p>\n".format(
nrows=n_rows, ncols=n_cols)
)
buf.write('</div>')
return buf.getvalue()
示例2: testFetchDataFrameCornerData
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def testFetchDataFrameCornerData(self):
max_rows = pd.get_option('display.max_rows')
try:
min_rows = pd.get_option('display.min_rows')
except KeyError: # pragma: no cover
min_rows = max_rows
sess = new_session()
for row in (5,
max_rows - 2,
max_rows - 1,
max_rows,
max_rows + 1,
max_rows + 2,
max_rows + 3):
pdf = pd.DataFrame(np.random.rand(row, 5))
df = DataFrame(pdf, chunk_size=max_rows // 2)
sess.run(df, fetch=False)
corner = fetch_corner_data(df, session=sess)
self.assertLessEqual(corner.shape[0], max_rows + 2)
corner_max_rows = max_rows if row <= max_rows else corner.shape[0] - 1
self.assertEqual(corner.to_string(max_rows=corner_max_rows, min_rows=min_rows),
pdf.to_string(max_rows=max_rows, min_rows=min_rows),
'failed when row == {}'.format(row))
示例3: test_nbinit_no_params
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def test_nbinit_no_params():
"""Test init_notebook defaults."""
ns_dict = {}
init_notebook(namespace=ns_dict, def_imports="nb")
check.is_in("pd", ns_dict)
check.is_in("get_ipython", ns_dict)
check.is_in("Path", ns_dict)
check.is_in("np", ns_dict)
# Note - msticpy imports throw when exec'd from unit test
# e.g. check.is_in("QueryProvider", ns_dict) fails
check.is_in("WIDGET_DEFAULTS", ns_dict)
check.equal(ns_dict["pd"].__name__, "pandas")
check.equal(ns_dict["np"].__name__, "numpy")
check.equal(pd.get_option("display.max_columns"), 50)
示例4: setUpClass
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def setUpClass(cls):
super(TestClipboard, cls).setUpClass()
cls.data = {}
cls.data['string'] = mkdf(5, 3, c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
cls.data['int'] = mkdf(5, 3, data_gen_f=lambda *args: randint(2),
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
cls.data['float'] = mkdf(5, 3,
data_gen_f=lambda r, c: float(r) + 0.01,
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
cls.data['mixed'] = DataFrame({'a': np.arange(1.0, 6.0) + 0.01,
'b': np.arange(1, 6),
'c': list('abcde')})
# Test GH-5346
max_rows = get_option('display.max_rows')
cls.data['longdf'] = mkdf(max_rows+1, 3, data_gen_f=lambda *args: randint(2),
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
cls.data_types = list(cls.data.keys())
示例5: get_engine
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def get_engine(engine):
""" return our implementation """
if engine == 'auto':
engine = get_option('io.parquet.engine')
if engine == 'auto':
# try engines in this order
try:
return PyArrowImpl()
except ImportError:
pass
try:
return FastParquetImpl()
except ImportError:
pass
if engine not in ['pyarrow', 'fastparquet']:
raise ValueError("engine must be one of 'pyarrow', 'fastparquet'")
if engine == 'pyarrow':
return PyArrowImpl()
elif engine == 'fastparquet':
return FastParquetImpl()
示例6: _repr_html_
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def _repr_html_(self): # pragma: no cover
"""repr function for rendering in Jupyter Notebooks like Pandas
Dataframes.
Returns:
The HTML representation of a Dataframe.
"""
num_rows = pandas.get_option("max_rows") or 60
num_cols = pandas.get_option("max_columns") or 20
# We use pandas _repr_html_ to get a string of the HTML representation
# of the dataframe.
result = self._build_repr_df(num_rows, num_cols)._repr_html_()
if len(self.index) > num_rows or len(self.columns) > num_cols:
# We split so that we insert our correct dataframe dimensions.
return result.split("<p>")[
0
] + "<p>{0} rows x {1} columns</p>\n</div>".format(
len(self.index), len(self.columns)
)
else:
return result
示例7: __repr__
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def __repr__(self):
num_rows = pandas.get_option("max_rows") or 60
num_cols = pandas.get_option("max_columns") or 20
temp_df = self._build_repr_df(num_rows, num_cols)
if isinstance(temp_df, pandas.DataFrame):
temp_df = temp_df.iloc[:, 0]
temp_str = repr(temp_df)
if self.name is not None:
name_str = "Name: {}, ".format(str(self.name))
else:
name_str = ""
if len(self.index) > num_rows:
len_str = "Length: {}, ".format(len(self.index))
else:
len_str = ""
dtype_str = "dtype: {}".format(temp_str.rsplit("dtype: ", 1)[-1])
if len(self) == 0:
return "Series([], {}{}".format(name_str, dtype_str)
return temp_str.rsplit("\nName:", 1)[0] + "\n{}{}{}".format(
name_str, len_str, dtype_str
)
示例8: print_table
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def print_table(table, name=None, fmt=None):
from IPython.display import display
if isinstance(table, pd.Series):
table = pd.DataFrame(table)
if isinstance(table, pd.DataFrame):
table.columns.name = name
prev_option = pd.get_option('display.float_format')
if fmt is not None:
pd.set_option('display.float_format', lambda x: fmt.format(x))
display(table)
if fmt is not None:
pd.set_option('display.float_format', prev_option)
示例9: test_num_rows_to_string
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def test_num_rows_to_string(self):
# check setup works
assert pd.get_option("display.max_rows") == 60
# Test eland.DataFrame.to_string vs pandas.DataFrame.to_string
# In pandas calling 'to_string' without max_rows set, will dump ALL rows
# Test n-1, n, n+1 for edge cases
self.num_rows_to_string(DEFAULT_NUM_ROWS_DISPLAYED - 1)
self.num_rows_to_string(DEFAULT_NUM_ROWS_DISPLAYED)
with pytest.warns(UserWarning):
# UserWarning displayed by eland here (compare to pandas with max_rows set)
self.num_rows_to_string(
DEFAULT_NUM_ROWS_DISPLAYED + 1, None, DEFAULT_NUM_ROWS_DISPLAYED
)
# Test for where max_rows lt or gt num_rows
self.num_rows_to_string(10, 5, 5)
self.num_rows_to_string(100, 200, 200)
示例10: test_num_rows_repr_html
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def test_num_rows_repr_html(self):
# check setup works
assert pd.get_option("display.max_rows") == 60
show_dimensions = pd.get_option("display.show_dimensions")
# TODO - there is a bug in 'show_dimensions' as it gets added after the last </div>
# For now test without this
pd.set_option("display.show_dimensions", False)
# Test eland.DataFrame.to_string vs pandas.DataFrame.to_string
# In pandas calling 'to_string' without max_rows set, will dump ALL rows
# Test n-1, n, n+1 for edge cases
self.num_rows_repr_html(pd.get_option("display.max_rows") - 1)
self.num_rows_repr_html(pd.get_option("display.max_rows"))
self.num_rows_repr_html(
pd.get_option("display.max_rows") + 1, pd.get_option("display.max_rows")
)
# Restore default
pd.set_option("display.show_dimensions", show_dimensions)
示例11: test_empty_dataframe_repr_html
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def test_empty_dataframe_repr_html(self):
# TODO - there is a bug in 'show_dimensions' as it gets added after the last </div>
# For now test without this
show_dimensions = pd.get_option("display.show_dimensions")
pd.set_option("display.show_dimensions", False)
ed_ecom = self.ed_ecommerce()
pd_ecom = self.pd_ecommerce()
ed_ecom_rh = ed_ecom[ed_ecom["currency"] == "USD"]._repr_html_()
pd_ecom_rh = pd_ecom[pd_ecom["currency"] == "USD"]._repr_html_()
# Restore default
pd.set_option("display.show_dimensions", show_dimensions)
assert ed_ecom_rh == pd_ecom_rh
示例12: test_use_bottleneck
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def test_use_bottleneck():
if nanops._BOTTLENECK_INSTALLED:
pd.set_option('use_bottleneck', True)
assert pd.get_option('use_bottleneck')
pd.set_option('use_bottleneck', False)
assert not pd.get_option('use_bottleneck')
pd.set_option('use_bottleneck', use_bn)
示例13: df
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def df(request):
data_type = request.param
if data_type == 'delims':
return pd.DataFrame({'a': ['"a,\t"b|c', 'd\tef´'],
'b': ['hi\'j', 'k\'\'lm']})
elif data_type == 'utf8':
return pd.DataFrame({'a': ['µasd', 'Ωœ∑´'],
'b': ['øπ∆˚¬', 'œ∑´®']})
elif data_type == 'string':
return mkdf(5, 3, c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
elif data_type == 'long':
max_rows = get_option('display.max_rows')
return mkdf(max_rows + 1, 3,
data_gen_f=lambda *args: randint(2),
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
elif data_type == 'nonascii':
return pd.DataFrame({'en': 'in English'.split(),
'es': 'en español'.split()})
elif data_type == 'colwidth':
_cw = get_option('display.max_colwidth') + 1
return mkdf(5, 3, data_gen_f=lambda *args: 'x' * _cw,
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
elif data_type == 'mixed':
return DataFrame({'a': np.arange(1.0, 6.0) + 0.01,
'b': np.arange(1, 6),
'c': list('abcde')})
elif data_type == 'float':
return mkdf(5, 3, data_gen_f=lambda r, c: float(r) + 0.01,
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
elif data_type == 'int':
return mkdf(5, 3, data_gen_f=lambda *args: randint(2),
c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
else:
raise ValueError
示例14: _ensure_decoded
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def _ensure_decoded(s):
""" if we have bytes, decode them to unicode """
if isinstance(s, (np.bytes_, bytes)):
s = s.decode(pd.get_option('display.encoding'))
return s
示例15: get_engine
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import get_option [as 别名]
def get_engine(engine):
""" return our implementation """
if engine == 'auto':
engine = get_option('io.parquet.engine')
if engine == 'auto':
# try engines in this order
try:
return PyArrowImpl()
except ImportError:
pass
try:
return FastParquetImpl()
except ImportError:
pass
raise ImportError("Unable to find a usable engine; "
"tried using: 'pyarrow', 'fastparquet'.\n"
"pyarrow or fastparquet is required for parquet "
"support")
if engine not in ['pyarrow', 'fastparquet']:
raise ValueError("engine must be one of 'pyarrow', 'fastparquet'")
if engine == 'pyarrow':
return PyArrowImpl()
elif engine == 'fastparquet':
return FastParquetImpl()