I am trying to work with pandas library if there a way possible to make the filename as a column name for example, my files names are with dates.
stock_2019-10-11.csv,
stock_2019-11-11.csv.
I want to make 2 different columns with the filenames and get the append the values something I expect to get out a CSV file as :
coulmns-primary_key, article_numerber,stock_2019-10-11,stock_2019-11-11
data-0 101,201,4,2
data-1 102,301,5,2
something like above, the new columns have values coming in from the CSV's merged.
import pandas as pd
import glob
import os
import sys
import csv
data = [] # pd.concat takes a list of dataframes
for csv in globbed_files(my directiry of files):
frame = pd.read_csv(csv,encoding='utf_16',error_bad_lines=False,index_col=False)
frame['filename'] = os.path.basename(csv)
data.append(frame)
frame1 = pd.concat(data, ignore_index=True
)