pandas df 排序 按列选取
# mlist = np.arange(0, math.ceil(max_eqMag), 0.1)
# df_b = df_b[df_b['eq_count']>0]
# print(df_b)
## df_b.sort_values("m",inplace=True,ascending=False)
#
# df_b['sum_count'] = df_b['eq_count'].cumsum()
## df_b = df_b[df_b['sum_count']>1]
序列排序 按索引,按值排序
s.sort_index()
s.sort_values()
遍历pd.Series的index和value的方法
for i, v in s.items():
print('index: ', i, 'value: ', v)
#index: a value: 1
#index: b value: 2
#index: c value: 3
#index: d value: 4
for i, v in s.iteritems():
print('index: ', i, 'value: ', v)
#index: a value: 1
#index: b value: 2
#index: c value: 3
#index: d value: 4
-
import pandas as pd
-
-
dict=[[1,2,3,4,5,6],[0,0,0,0,0,0]]
-
data=pd.DataFrame(dict)
-
print(data)
-
for indexs in data.index:
-
print(data.loc[indexs].values[0:-1])
( 按行遍历数据)
-
import pandas as pd
-
-
dict=[[1,2,3,4,5,6],[0,0,0,0,0,0]]
-
data=pd.DataFrame(dict)
-
print(data)
-
for indexs in data.columns:
-
print(data[indexs])
(按列遍历数据)
for row in d_new.iterrows():
# print(row[1]['t_d'])
Nu.append(d_new[d_new['t_d']>=row[1]['t_d']].count())