我有一个数据框,想从其中一列中获取值的平均值。如果我做:
print df['col_name'][0:1]
print df['col_name'][0:1].mean()
我得到:
0 2
Name: col_name
2.0
如果我做:
print df['col_name'][0:2]
print df['col_name'][0:2].mean()
我得到:
0 2
1 1
Name: col_name
10.5
如果我做:
print df['col_name'][0:3]
print df['col_name'][0:3].mean()
我得到:
0 2
1 1
2 2
Name: col_name
70.6666666667