Reputation: 39
So I have a dictionary of 98 elements and I need to write each key:value to a CSV file.
For example:
{'Group1':values,'Group2':values}, etc...
So in this example I would need two (2) csv files:
I am thinking I need a for loop but I am getting a little stuck:
for element in DataFrameDict:
element.to_csv(f'{element}_output.csv')
Upvotes: 0
Views: 429
Reputation: 791
Try this since your data is stored in a dict:
for key, values in dict.items():
f = open("{}_output.csv".format(key),"w")
f.write(key)
for i in values:
f.write("," + str(i))
f.close()
Upvotes: 2