pandas docs

  • 根据某一列的值进行筛选axis=0
train = pd.read_csv('../input/train.csv')
train.head()

train = pd.read_csv(‘../input/train.csv’)

id name
0 harry
1 william

我们筛选name=”harry”的行

train.loc[data['name'] = 'harry']
  • 使用max()查找索引轴上的最大值
import pandas as pd 
df = pd.DataFrame({"A":[12, 4, 5, 44, 1], 
                   "B":[5, 2, 54, 3, 2], 
                   "C":[20, 16, 7, 3, 8],  
                   "D":[14, 3, 17, 2, 6]}) 
df 
A B C D
0 12 5 20 14
1 4 2 16 3
2 5 54 7 17
3 44 3 3 2
4 1 2 8 6
默认axis = 0
df.max(axis = 0) 
A 44
B 54
C 20
D 17
  • 根据某一列的值进行筛选axis=1
df = pd.DataFrame({"A":[12, 4, 5, None, 1],  
                   "B":[7, 2, 54, 3, None], 
                   "C":[20, 16, 11, 3, 8], 
                   "D":[14, 3, None, 2, 6]}) 
//skip the Na values while finding the maximum 
df.max(axis = 1, skipna = True) 
0 20.0
1 16.0
2 54.0
3 3.0
4 8.0
  • 按照某一列的值,画直方图,统计各个值的分布情况
import matplotlib.pyplot as plt
train['none'].value_counts().plot.bar()
plt.show()
Avatar photo

About Blackford

这是个最好的时代,这是个最坏的时代,这是个充满希望的春天,这是个令人绝望的冬天,我们前面什么都有,我们前面什么都没有。梦想,让我们一次次的走远,又一次次的回头,一个关于人生的梦想还在不断奔跑,带着喜悦和疼痛,不过一切才刚刚开始,并且直到今天也远远没有结束
This entry was posted in AI. Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用*标注