4
超强图解 Pandas,建议收藏
source link: https://www.51cto.com/article/716991.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
超强图解 Pandas,建议收藏
2022-08-24 11:54:10
本文将借助可视化的过程,讲解Pandas的各种操作。一起来看一下吧。
Pandas是数据挖掘常见的工具,掌握使用过程中的函数是非常重要的。
sort_values
(dogs[dogs['size'] == 'medium']
.sort_values('type')
.groupby('type').median()
)
执行步骤:
- size列筛选出部分行
- 然后将行的类型进行转换
- 按照type列进行分组,计算中位数
selecting a column
dogs['longevity']
groupby + mean
dogs.groupby('size').mean()
执行步骤:
- 将数据按照size进行分组
- 在分组内进行聚合操作
grouping multiple columns
dogs.groupby(['type', 'size'])
groupby + multi aggregation
(dogs
.sort_values('size')
.groupby('size')['height']
.agg(['sum', 'mean', 'std'])
)
- 按照size列对数据进行排序
- 按照size进行分组
- 对分组内的height进行计算
filtering for columns
df.loc[:, df.loc['two'] <= 20]
filtering for rows
dogs.loc[(dogs['size'] == 'medium') & (dogs['longevity'] > 12), 'breed']
dropping columns
dogs.drop(columns=['type'])
joining
ppl.join(dogs)
merging
ppl.merge(dogs, left_on='likes', right_on='breed', how='left')
pivot table
dogs.pivot_table(index='size', columns='kids', values='price')
melting
dogs.melt()
pivoting
dogs.pivot(index='size', columns='kids')
stacking column index
dogs.stack()
unstacking row index
dogs.unstack()
resetting index
dogs.reset_index()
setting index
dogs.set_index('breed')
责任编辑:庞桂玉
来源:
Python开发者
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK