I have 2/ more csv files in folder and I want to import those files to different data frame and want to rename data frame as per file name.
import os
import pandas as pd
redShiftKeyFolderPath = r'D:\Sunil_Work\temp8\Prod_IMFIFSS2017' # contains 2 csv files i.e Prod_IMFIFSS2017_Indicator.csv & Prod_IMFIFSS2017_Location.csv
def importRedshiftKeys(redShiftKeyFolderPath):
for file in os.listdir(redShiftKeyFolderPath):
if file.endswith('.csv'):
redShiftKey = pd.read_csv(os.path.join(redShiftKeyFolderPath, file), dtype = object) # importing
i = file.rfind('_'); file = file[i:]; rDfName = 'redShiftKey_' + file.replace('_', '').replace('.csv', '') # taking last part of the file name after _ & excluding .csv
print('Need to rename dataframe as: ', rDfName)
# Here i want to rename dataframe: "redShiftKey" with new name stored in "rDfName"
return
importRedshiftKeys(redShiftKeyFolderPath)
I expect 2 data frame i.e redShiftKey_Indicator & redShiftKey_Location