本文整理匯總了Python中pandas.core.frame.DataFrame.sort_index方法的典型用法代碼示例。如果您正苦於以下問題:Python DataFrame.sort_index方法的具體用法?Python DataFrame.sort_index怎麽用?Python DataFrame.sort_index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.frame.DataFrame
的用法示例。
在下文中一共展示了DataFrame.sort_index方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: stack_sparse_frame
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import sort_index [as 別名]
def stack_sparse_frame(frame):
"""
Only makes sense when fill_value is NaN
"""
lengths = [s.sp_index.npoints for _, s in compat.iteritems(frame)]
nobs = sum(lengths)
# this is pretty fast
minor_labels = np.repeat(np.arange(len(frame.columns)), lengths)
inds_to_concat = []
vals_to_concat = []
# TODO: Figure out whether this can be reached.
# I think this currently can't be reached because you can't build a
# SparseDataFrame with a non-np.NaN fill value (fails earlier).
for _, series in compat.iteritems(frame):
if not np.isnan(series.fill_value):
raise TypeError('This routine assumes NaN fill value')
int_index = series.sp_index.to_int_index()
inds_to_concat.append(int_index.indices)
vals_to_concat.append(series.sp_values)
major_labels = np.concatenate(inds_to_concat)
stacked_values = np.concatenate(vals_to_concat)
index = MultiIndex(levels=[frame.index, frame.columns],
labels=[major_labels, minor_labels],
verify_integrity=False)
lp = DataFrame(stacked_values.reshape((nobs, 1)), index=index,
columns=['foo'])
return lp.sort_index(level=0)
示例2: len
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import sort_index [as 別名]
# pp.savefig()
#
# plt.clf()
# plt.cla()
# plt.scatter(dailyrets[:,marketsymbolpos],dailyrets[:,sym],c='blue') # $SPX v XOM
# plt.ylabel(symbols[sym])
# plt.xlabel(symbols[marketsymbolpos])
# pp.savefig()
sym_todo = len(close.columns) - sym - 1
print str(sym_todo) + " to do!"
plt.clf()
plt.cla()
#take out stocks with nana > 10%
#for sym in symbols:
# if sharperatios['NaNs'][sym] > 0.1:
# sharperatios.
sharperatios = sharperatios.sort_index(by = 'sr', ascending = False)
sharperatios = sharperatios[0:10]
plt.figure()
sharperatios.plot()
pp.savefig()
pp.close()