读入数据
import pandas as pdreviews = pd.read_csv("../input/wine-reviews/winemag-data-130k-v2.csv", index_col=0)
# 第一种 相当于把元组转成字典# renamed = reviews.rename(columns=dict(region_1='region',region_2='locale'))# 第二种renamed = reviews.rename(columns={'region_1':'region','region_2':'locale'})renamed.head()
# reindexed = reviews.rename_axis('wines', axis='rows')# reindexed.head()# 另一种有意思的改法redo = reviews.rename(index={1:'A',2:'B'},columns={'region_1':'region'})redo.head()
先读入两个数据集 查看数据集情况:
gaming_products = pd.read_csv("../input/things-on-reddit/top-things/top-things/reddits/g/gaming.csv")gaming_products['subreddit'] = "r/gaming"movie_products = pd.read_csv("../input/things-on-reddit/top-thin爱情语录gs/top-things/reddits/m/movies.csv")movie_products['su网络编辑员breddit'] = "r/movies"# gaming_products# print()movie_products
然后连接两个数据集:
combined_products = pd.concat([gaming_products, movie_products],axis=0,keys=['x','y'])combined_products'''Attention: axis=0 : 表示在纵轴(列)进行连接 axis=1 : 表示在横轴(行)进行连接 keys=['x','y'] : 进行表示 连接后的数据集中的数据分别是来自哪部分 具体可见下图 '''
powerlifting_meets = pd.read_csv("../input/powerlifting-databa/meets.csv")powerlifting_competitors = pd.read_csv("../input早上好问候语温馨短句/powerlifting-databa/openpowerlifting.csv")powerlifting_competitors
然后进行主键连接:
powerlifting_combined = powerlifting_meets.t_index("MeetID").join(powerlifting_competitors.t_index("MeetID"))powerlifting_combined
注明:
以上数据来自kaggle learn
Pandas Renaming and combining workbook
本文地址:https://blog键盘突然打不出字怎么回事.csdn.net/liuhehe123/article/details/8593061《沁园春雪》1
本文发布于:2023-04-04 05:40:45,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/c251d067117580ed10bd83d983729d78.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Pandas六、重命名和联合.doc
本文 PDF 下载地址:Pandas六、重命名和联合.pdf
留言与评论(共有 0 条评论) |