Home > OS >  Pandas: How do I read specific columns in a file and make them into a new csv
Pandas: How do I read specific columns in a file and make them into a new csv

Time:09-23

Here is sample 1 :

| district_id | date        |
| --------    | ----------- |
| 18          | 1995-03-24  |
| 1           | 1993-02-26  |

Sample 2:

| link_id   | type        |
| --------  | ----------- |
| 9         | gold        |
| 19        | classic     |

I want to gather sample 1's date column and sample 2's type column and output them as data.csv

CodePudding user response:

You can use vertical concatenation of dataframes and then render it:

df3 = pandas.concat([df1['date'], df2['type']], axis = 1)
df3.to_csv('data.csv')
  • Related