So, I have a directory with .csv files. For example:
a.csv
id,name
1,john
2,mary
3,alex
b.csv
id,birth
1,01.01.2001
2,05.06.1990
c.csv
id,death
2,01.02.2020
1,-
The result should be one dict where the key is id (int) and value is a dict of all the different values across the the files(dict of dicts). Something like this:
{
1: {"id": 1, "name": "john", "birth": "01.01.2001", "death": -},
2: {"id": 2, "name": "mary", "birth": "05.06.1990",
"death": "01.02.2020"},
3: {"id": 3, "name": "alex", "birth": None, "death": None},
}
So far I've tried to merge all files into one dataframe:
from pathlib import Path
import os
import pandas as pd
files = Path(r'path').rglob('*.csv')
# read in all the csv files
all_csvs = [pd.read_csv(file) for file in files]
# lump into one table
all_csvs = pd.concat(all_csvs, axis=1)
But as a result I get a dataframe where 'id' is repeated in three columns.
Any help will be appreciated!