I'm trying to read a bunch of csvs into pandas using a for loop. I want the table names to be the last bit of the full file path before the extension. For example,
ACS_BV0002_2016_Age.csv
would be
Age
I am doing this so I can create dictionaries with the table name as a key and the column names and data types as values, which I can then use in psycogpg2 to create all of my tables in postgresql in one fell swoop.
This seems to get the name i want:
path = r"C:\Data\Waste_Intervention\Census_Tables\Cleaned"
fList = os.listdir(path)
for doc in fList:
csv = "{}\\{}".format(path, doc)
name = doc.split("_")[-1][:-4]
pd.read_csv(csv)
Is there a way I can use the output of name
become the variable name for the dataframe read in by pd.read_csv
?