I have some different csv files in a same folder with this structure:
CSV 1:
Name Passes Shots
1 Player 1 20 5
2 Player 2 30 6
3 Player 3 10 3
CSV 2:
Name Goals Duels
1 Player 3 2 3
2 Player 1 0 2
3 Player 2 1 7
CSV 3:
Name Country Age
1 Player 2 SPA 25
2 Player 3 SPA 26
3 Player 1 USA 23
I would like to combine this csvs in one dataframe with pandas and the result I want would be:
Name Passes Shots Goals Duels Country Age
1 Player 1 20 5 0 2 USA 23
2 Player 2 30 6 1 7 SPA 25
3 Player 3 10 3 2 3 SPA 26
I'm trying to combine them with this code but i get a dataframe with 9 rows (Player 1 3 times, Player 2 3 times and Player 3 3 times):
file_extension = ".csv"
all_filenames = [i for i in glob.glob(f"*{file_extension}")]
df = pd.concat([pd.read_csv(file) for file in all_filenames])
The result I get is something like:
Name Passes Shots Goals Duels Country Age
1 Player 1 20 5 NaN NaN NaN NaN
2 Player 2 30 6 NaN NaN NaN NaN
3 Player 3 10 3 NaN NaN NaN NaN
1 Player 1 NaN NaN 0 2 NaN NaN
2 Player 2 NaN NaN 1 7 NaN NaN
3 Player 3 NaN NaN 2 3 NaN NaN
1 Player 1 NaN NaN NaN NaN USA 23
2 Player 2 NaN NaN NaN NaN SPA 25
3 Player 3 NaN NaN NaN NaN SPA 26
Any idea of how to combine them as I want, with the name as the reference? Thanks in advance!