Is it possible to return multiple df
's to independent csv's
without using .to_csv
. Using the code below I'm manually returning desired values and exporting those to a csv. This is ok if I only have a few files to export but if there's numerous files or file names that constantly change over datasets it can be cumbersome.
Is there a more efficient way to return desired values if you have a specific value list and export those to a csv?
import pandas as pd
d = ({
'C' : ['08:00:00','XX','08:10:00','XX','08:41:42','XX','08:50:00','XX', '09:00:00', 'XX','09:15:00','XX','09:21:00','XX','09:30:00','XX','09:40:00','XX'],
'D' : ['Home','Home','Home','Home','Away','Away','Shops','Shops','Away','Away','Shops','Shops','Home','Home','Away','Away','Home','Home'],
'E' : ['Num:','','Num:','','Num:','','Num:','','Num:', '','Num:','','Num:','','Num:', '','Num:', ''],
'F' : ['1','','1','','1','','1','','1', '','2','','2','','1', '','2',''],
'A' : ['A','','A','','A','','A','','A','','A','','A','','A','','A',''],
'B' : ['Stop','','Res','','Stop','','Start','','Res','','Stop','','Res','','Start','','Start','']
})
df = pd.DataFrame(data=d)
#List of designated places
values = ['Home', 'Away', 'Shops']
#Export to csv
Home = df.loc[df['D'] == 'Home'].to_csv('Home.csv')
Away = df.loc[df['D'] == 'Away'].to_csv('Away.csv')
Shops = df.loc[df['D'] == 'Shops'].to_csv('Shops.csv')