I have two dataframes test1 and test2. My program logic is like below
def write_file():
test1.to_csv(('test1.csv'),index=None)
def process_file():
test2= pd.read_csv('test1.csv',low_memory=False)
def write_processed_file():
test2.to_csv(('test2.csv'),index=None)
I invoke all the above functions like below
write_file()
process_file()
write_processed_file()
As you can see, I have two write functions just to write the dataframe because I want the .csv file names to be different for both the dataframes. If I follow the below input argument approach to have just one write function then I can have only one common file name. How do we get the datframe name?
def write_file(df_name):
df_name.to_csv(('common_file_name.csv'),index=None)
I expect my output to have two csv files with the name test1.csv and test2.csv without having two write functions
Basically I have 400-500 lines of code where has 15-18 lines if code to write dataframe to csv files. I would like to have one write function which accepts dataframe as input and provides the name of the dataframe as csv file name.
Is there anyway to get the dataframe name and save the file with the same name in a elegant and efficient manner?