I have two pandas dataframes: one:
import pandas as pd
df1 = pd.read_csv('filename1.csv')
df1
A B
0 1 22
1 2 15
2 5 99
3 6 1
....
and two
df2 = pd.read_csv('filename1.csv')
df2
A B
0 1 6
1 3 52
2 4 15
3 5 62
...
I would like to merge these dataframes into a single dataframe, with column A
as the index for this new dataframe.
The columns are filenames, the rows are the values for 'A'.
If values do not exist for these index, NaN
then exists. The column names should be the filenames from the *csv above.
filename1 filename2
1 22 6
2 15 NaN
3 NaN 52
4 NaN 15
5 99 62
6 1 NaN
How does one do this? For two files, one could use pandas.merge()
, but what is dozens of the orginal dataframes exists?