I am trying to create multiple empty pandas dataframes in the following way:
dfnames = ['df0', 'df1', 'df2']
x = pd.Dataframes for x in dfnames
The above mentionned line returns error syntax. What would be the correct way to create the dataframes?
to connect the names in fdnames to the dataframes, use e.g. a dict:
dataFrames = {(name, pd.DataFrame()) for name in dfnames}
You can't have many data frames within a single variable name, here you are trying to save all empty data frames in x. Plus, you are using wrong attribute name, it is pd.DataFrame and not pd.Dataframes.
I did this and it worked-
dfnames = ['df0', 'df1', 'df2']
x = [pd.DataFrame for x in dfnames]
df = [ pd.DataFrame() for _ in range(3) ]and then you have list withdf[0],df[1],df[2]dictuse -{x:pd.DataFrame() for x in dfnames}. Note the extra-parenthesis when calling an empty dataframe.