OK, this might be a very silly question, but...
I have an object x, which contains a number of pandas dataframes (df1,df2,df3 for sake of argument)
When the program has finished running, I want to export each of these dataframes to its own csv file. At the moment, I have a function within x that looks like this:
def export(self, path):
self.df1.to_csv(path+"_df1.csv")
self.df2.to_csv(path+"_df2.csv")
self.df3.to_csv(path+"_df3.csv")
It works (I can just use x.export(somepath), but I keep having to change it because the data I want to keep in the object changes. Can anybody tell me if there is a way of simply iterating over all of the variables within an object (they are all the same format) and (in this case) dumping them all to their respective .csv files?
Thanks
dataframes, which is a list holding the dataframes?self.dataframes = [pd.DataFrame(), pd.DataFrame(), ...]in__init__and instead of accessinginstance.df1you would useinstance.dataframes[0]. (Of course, you could alsopopandappendfrom that list.)