I'm working with a lot of different files and after I am done editing I want to save it as a new csv file.
print(files[0])
mhofmanmusselsT1_1L.raw
# I want the csv file for this dataset to be namend waves_T1_1L.csv,
# but if I select a files[3] it would be waves_T3_2S.csv
t = files[0]
testtype = t[14:19]
name= ("waves_"+testtype)
Using the to_csv
code it uses the df name as the file name. I'am quite new to python so it might be something obvious but is there a way to use
print(name)
waves_T1_1L
name = pd.DataFrame(df)
#Where name would function like if "print(name)" would be used,
#so it will automatically update if a different "files[n]" would be used.
#Unfortunately it won't allow me to do that.
UPDATE I have figured it out it took more steps than I expected.
Name = files[0]
testtype = Name[14:19]
filename = "waves_"+ testtype
wavedata.to_csv('out.csv')
old_name= r"workdirectory/out.csv"
new_name= r"workdirectory"+filename+".csv"
os.rename(old_name,new_name)
The output file will be changed from out.csv to waves_T1_1L.csv and it is updated if a different file is selected as input.