Skip to content Skip to sidebar Skip to footer

Try To Include A Column Based On Input And File Name In Pandas Dataframe In Python

I have a several csv files which have the following structure: Erster Hoch Tief Schlusskurs Stuecke Volumen Datum

Solution 1:

You can add column by just assigning a value to it:

df['new_column'] = 'string'

All together:

import pandas as pd

wkn_list_dummy = {'A0YAQA','A1EWWW'}

final_df = pd.DataFrame()
for w_list in wkn_list_dummy:
    url = 'C:/wkn_'+str(w_list)+'_historic.csv'
    df = pd.read_csv(url, encoding='cp1252', sep=';', decimal=',', index_col=0)
    df['wkn'] = w_list
    final_df = final_df.append(df)
final_df.reset_index(inplace=True) 
print(final_df)

Post a Comment for "Try To Include A Column Based On Input And File Name In Pandas Dataframe In Python"