I have plenty of csvs that look like this:
I want to rename column names because they are too long and to insert new column named Company with same values (eg. aapl (ticker for Apple)). Here's the code how I did that:
data = pd.read_csv('aapl.csv', index_col=0)
data.insert(0, 'Company', 'aapl')
data.rename(columns={'Unnamed: 0': 'Company', 'Working Capital / Total Assets':'WC/TA', 'Retained Earnings / Total Assets': 'RE/TA', 'EBIT / Total Assets':'EB/TA','Current Market Cap / Total Liabilites':'MC/TL', 'Revenue / Total Assets':'RV/TA','Net Income / Total Assets (ROA)':'NI/TA', 'Total Liabilites / Total Assets':'TL/TA', 'Current Assets / Current Liabilites':'CA/CL'})
data.to_csv('aapl.csv')
and I get
Thing is, I have 278 other companies in same csv format (imb.csv, ase.csv, wire.csv etc.) and I would like to rename/insert columns for all of them in the same way. Finaly, I need to merge all these csv files into one csv (that is the reason why is new column "Company" needed).
My question is, how to create new column (name: Company) and populate it with name of the file.
For example: load ibm.csv -> rename columns -> add new column (Company) -> insert value ibm (filename/ticker) in column Company -> export to csv.