本文整理匯總了Python中pandas.set_option方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.set_option方法的具體用法?Python pandas.set_option怎麽用?Python pandas.set_option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas
的用法示例。
在下文中一共展示了pandas.set_option方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print_para
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def print_para(model):
"""
Prints parameters of a model
:param opt:
:return:
"""
st = {}
total_params = 0
total_params_training = 0
for p_name, p in model.named_parameters():
# if not ('bias' in p_name.split('.')[-1] or 'bn' in p_name.split('.')[-1]):
st[p_name] = ([str(x) for x in p.size()], np.prod(p.size()), p.requires_grad)
total_params += np.prod(p.size())
if p.requires_grad:
total_params_training += np.prod(p.size())
pd.set_option('display.max_columns', None)
shapes_df = pd.DataFrame([(p_name, '[{}]'.format(','.join(size)), prod, p_req_grad)
for p_name, (size, prod, p_req_grad) in sorted(st.items(), key=lambda x: -x[1][1])],
columns=['name', 'shape', 'size', 'requires_grad']).set_index('name')
print('\n {:.1f}M total parameters. {:.1f}M training \n ----- \n {} \n ----'.format(total_params / 1000000.0,
total_params_training / 1000000.0,
shapes_df.to_string()),
flush=True)
return shapes_df
示例2: daily_stats
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def daily_stats(data: (pd.Series, pd.DataFrame), **kwargs) -> pd.DataFrame:
"""
Daily stats for given data
Examples:
>>> pd.set_option('precision', 2)
>>> (
... pd.concat([
... pd.read_pickle('xbbg/tests/data/sample_rms_ib0.pkl'),
... pd.read_pickle('xbbg/tests/data/sample_rms_ib1.pkl'),
... ], sort=False)
... .pipe(get_series, col='close')
... .pipe(daily_stats)
... )['RMS FP Equity'].iloc[:, :5]
count mean std min 10%
2020-01-16 00:00:00+00:00 434.0 711.16 1.11 708.6 709.6
2020-01-17 00:00:00+00:00 437.0 721.53 1.66 717.0 719.0
"""
if data.empty: return pd.DataFrame()
if 'percentiles' not in kwargs: kwargs['percentiles'] = [.1, .25, .5, .75, .9]
return data.groupby(data.index.floor('d')).describe(**kwargs)
示例3: execute
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def execute(cls, ctx, op: "DataFrameDropNA"):
try:
pd.set_option('mode.use_inf_as_na', op.use_inf_as_na)
in_data = ctx[op.inputs[0].key]
if op.drop_directly:
if in_data.ndim == 2:
result = in_data.dropna(axis=op.axis, how=op.how, thresh=op.thresh,
subset=op.subset)
else:
result = in_data.dropna(axis=op.axis, how=op.how)
ctx[op.outputs[0].key] = result
return
in_counts = ctx[op.inputs[1].key]
if op.how == 'all':
in_counts = in_counts[in_counts > 0]
else:
thresh = op.subset_size if op.thresh is None else op.thresh
in_counts = in_counts[in_counts >= thresh]
ctx[op.outputs[0].key] = in_data.reindex(in_counts.index)
finally:
pd.reset_option('mode.use_inf_as_na')
示例4: execute
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def execute(cls, ctx, op):
try:
pd.set_option('mode.use_inf_as_na', op.use_inf_as_na)
if op.stage == OperandStage.map:
cls._execute_map(ctx, op)
elif op.stage == OperandStage.combine:
cls._execute_combine(ctx, op)
else:
input_data = ctx[op.inputs[0].key]
value = getattr(op, 'value', None)
if isinstance(op.value, (Base, Entity)):
value = ctx[op.value.key]
ctx[op.outputs[0].key] = input_data.fillna(
value=value, method=op.method, axis=op.axis, limit=op.limit, downcast=op.downcast)
finally:
pd.reset_option('mode.use_inf_as_na')
示例5: execute
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def execute(cls, ctx, op: "DataFrameAggregate"):
try:
pd.set_option('mode.use_inf_as_na', op.use_inf_as_na)
if op.stage == OperandStage.map:
cls._execute_map(ctx, op)
elif op.stage == OperandStage.combine:
cls._execute_combine(ctx, op)
elif op.stage == OperandStage.agg:
cls._execute_agg(ctx, op)
elif op.raw_func == 'size':
xp = cp if op.gpu else np
ctx[op.outputs[0].key] = xp.array(ctx[op.inputs[0].key].agg(op.raw_func, axis=op.axis)) \
.reshape(op.outputs[0].shape)
else:
ctx[op.outputs[0].key] = ctx[op.inputs[0].key].agg(op.raw_func, axis=op.axis)
finally:
pd.reset_option('mode.use_inf_as_na')
示例6: job_table
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def job_table(self, project=None, recursive=True, columns=None, all_columns=False, sort_by="id", max_colwidth=200,
job_name_contains=''):
if project is None:
project = self._project
if columns is None:
columns = ["job", "project", "chemicalformula"]
if all_columns:
columns = self._columns
if len(self._job_table) != 0:
if recursive:
df = self._job_table[self._job_table.project.str.contains(project)]
else:
df = self._job_table[self._job_table.project == project]
else:
df = self._job_table
pandas.set_option("display.max_colwidth", max_colwidth)
if len(df) == 0:
return df
if job_name_contains != '':
df = df[df.job.str.contains(job_name_contains)]
if sort_by in columns:
return df[columns].sort_values(by=sort_by)
return df[columns]
示例7: write_to_html
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def write_to_html(self):
pandas.set_option('display.max_colwidth', -1)
header = '{!s}'.format(self.df.index.tolist()[0])
df = self.df.reset_index(level=['Clf.', 'Set_Type', 'Eval.'])
if '#Rep.' in df:
df.drop('#Rep.', 1, inplace=True)
df.drop('Eval.', 1, inplace=True)
df.drop('Set_Size', 1, inplace=True)
df.drop('Set_Type', 1, inplace=True)
df.drop('f1', 1, inplace=True)
df.drop('precision', 1, inplace=True)
df.columns = ['Clf', '\\ac{DGA} Type', '\\ac{ACC}', '\\ac{TPR}', '\\ac{TNR}', '\\ac{FNR}', '\\ac{FPR}']
fname = settings.ANALYSIS_FOLDER + '/eval_full.html'
with open(fname, 'w') as f:
f.write(df.to_html())
pandas.reset_option('display.max_colwidth')
示例8: rsi
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def rsi(df, n=6):
"""
相對強弱指標(Relative Strength Index,簡稱RSI
LC= REF(CLOSE,1)
RSI=SMA(MAX(CLOSE-LC,0),N,1)/SMA(ABS(CLOSE-LC),N1,1)×100
SMA(C,N,M)=M/N×今日收盤價+(N-M)/N×昨日SMA(N)
"""
# pd.set_option('display.max_rows', 1000)
_rsi = pd.DataFrame()
_rsi['date'] = df['date']
px = df.close - df.close.shift(1)
px[px < 0] = 0
_rsi['rsi'] = sma(px, n) / sma((df['close'] - df['close'].shift(1)).abs(), n) * 100
# def tmax(x):
# if x < 0:
# x = 0
# return x
# _rsi['rsi'] = sma((df['close'] - df['close'].shift(1)).apply(tmax), n) / sma((df['close'] - df['close'].shift(1)).abs(), n) * 100
return _rsi
示例9: bbiboll
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def bbiboll(df, n=10, k=3):
"""
BBI多空布林線 bbiboll(10,3)
BBI={MA(3)+ MA(6)+ MA(12)+ MA(24)}/4
標準差MD=根號[∑(BBI-MA(BBI,N))^2/N]
UPR= BBI+k×MD
DWN= BBI-k×MD
"""
# pd.set_option('display.max_rows', 1000)
_bbiboll = pd.DataFrame()
_bbiboll['date'] = df.date
_bbiboll['bbi'] = (_ma(df.close, 3) + _ma(df.close, 6) + _ma(df.close, 12) + _ma(df.close, 24)) / 4
_bbiboll['md'] = _md(_bbiboll.bbi, n)
_bbiboll['upr'] = _bbiboll.bbi + k * _bbiboll.md
_bbiboll['dwn'] = _bbiboll.bbi - k * _bbiboll.md
return _bbiboll
示例10: df_to_string
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def df_to_string(df):
"""
Create a formatted str representation of the DataFrame.
Parameters
----------
df: DataFrame
Returns
-------
str
"""
pd.set_option('display.expand_frame_repr', False)
pd.set_option('precision', 8)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)
return df.to_string()
示例11: list_groups
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def list_groups(dim=3):
"""
Function for quick print of groups and symbols
Args:
group: the group symbol or international number
dim: the periodic dimension of the group
"""
import pandas as pd
keys = {3: 'space_group',
2: 'layer_group',
1: 'rod_group',
0: 'point_group',
}
data = symbols[keys[dim]]
df = pd.DataFrame(index=range(1, len(data)+1),
data=data,
columns=[keys[dim]])
pd.set_option('display.max_rows', len(df))
#df.set_index('Number')
print(df)
示例12: _set_display_options
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def _set_display_options(self):
"""
Set pandas display options. Display all rows and columns by default.
"""
display_options = {'display.max_rows': None,
'display.max_columns': None,
'display.width': None,
'display.max_colwidth': None}
for k in display_options:
try:
pd.set_option(k, display_options[k])
except ValueError:
msg = """Newer version of Pandas required to set the '{}'
option.""".format(k)
warnings.warn(msg)
示例13: configure_tests
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def configure_tests():
pd.set_option('chained_assignment', 'raise')
# For running doctests: make np and pd names available
示例14: test_format_sparse_config
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_option [as 別名]
def test_format_sparse_config(idx):
warn_filters = warnings.filters
warnings.filterwarnings('ignore', category=FutureWarning,
module=".*format")
# GH1538
pd.set_option('display.multi_sparse', False)
result = idx.format()
assert result[1] == 'foo two'
tm.reset_display_options()
warnings.filters = warn_filters
示例15: test_use_bottleneck
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import set_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)