How To Join Dataframes Without Losing Their Names
how to join dataframes without losing their names I have several dataframes in a list and by joining them I am losing the identification of each one because they have equal columns
Solution 1:
Use add_sufix
when reading.
pd_list = [pd.read_csv(f'{ticker}.csv').add_suffix(ticker) for ticker in ticker_list]
OR you can concat
through axis=0
and define the ticker as another columns
pd_list = [pd.read_csv(f'{ticker}.csv').assign(ticker=ticker) for ticker in ticker_list]
df = pd.concat(pd_list)
Post a Comment for "How To Join Dataframes Without Losing Their Names"