# 数据分析利器——python中pandas的使用（2）

2021/8/21 20:55:53 浏览：

DataFrame

``````DataFrame(data=np.random.randint(0,10,size=(3,5)))
``````

01234
020184
167753
225455

``````DataFrame(data=np.random.randint(60,100,size=(3,6)),index=['一模','二模','三模'],columns=['语文','数学','英语','物理','化学','生物'])
``````

``````df = DataFrame(data=np.random.randint(60,100,size=(3,6)),index=['一模','二模','三模'],columns=['语文','数学','英语','物理','化学','生物'])
df.loc['三模','生物']
``````

``````df.loc[['三模','二模','一模'],'生物']
``````

1. 索引对齐
2. 广播
``````# 广播运算
df+5
df+df
``````

Series和DataFrame能进行运算嘛

``````score = df.loc['一模']
score
df+score
``````

axis=0表示纵向级联，axis=1表示横向级联，默认为0

``````df.add(score,axis=1)
``````

``````df.add(score,axis=0)
``````

1. 求和
2. 求平均值
3. 求方差

``````# 求和
score.sum()
# 平均值
score.mean()
# 方差
score.var()
# 标准差
score.std()
# 最大值
score.max()
# 最小值
score.min()
``````

``````df.sum()
``````
``````语文    243

dtype: int64
``````

``````df.sum(axis=1)
``````
``````一模    508

dtype: int64
``````

1. any
2. all
``````df.isnull()
``````

``````# 全部为真才是真
(score>10000).all()
# 若至少一个值为真则为真
(score>10000).any()
``````