超强图解Pandas
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')
文章原文:https://pandastutor.com/index.html
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。