简体   繁体   English

如何将多个不同的 CSV 文件与外键合并?

[英]How can I merge multiple different CSV files with foreign keys?

Good Evening, I've been trying to work with the Instacart Dataset as a part of my online classes using Jupyter Notebook (Python);晚上好,我一直在尝试使用 Instacart 数据集作为我使用 Jupyter Notebook (Python) 在线课程的一部分; one of the requirements is to merge all of the files (that come mostly with different columns and one or two foreign keys) into one big CSV, like in this case:要求之一是将所有文件(主要带有不同的列和一两个外键)合并到一个大的 CSV 中,就像在这种情况下:

https://github.com/gabrielhpr/InstacartClustering/blob/master/InstacartClustering.ipynb https://github.com/gabrielhpr/InstacartClustering/blob/master/InstacartClustering.ipynb

However I don't know how to accomplish that, each file comes with a foreign key so I guess that's the way to go, but how do you match those foreign keys to the correct rows and compile all the CSV files?但是我不知道如何做到这一点,每个文件都带有一个外键,所以我想这就是 go 的方式,但是你如何将这些外键匹配到正确的行并编译所有 CSV 文件?

Yes you can it very easily是的,你可以很容易地做到

  1. Set the index column as foreign keys将索引列设置为外键

    df.set_index(foreign_key)

  2. use pd.concat([df1,df2],axis=1) to merge those two dataframes.使用pd.concat([df1,df2],axis=1)合并这两个数据框。

Using these two processes you will be able to merge those two CSV files with a foreign key.使用这两个过程,您将能够将这两个 CSV 文件与外键合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM