I would like to change all the columns of my data frame into a csv file
I would like to change all the columns of my data frame into a csv file
I am trying to change each column of my data frame into csv format and I think the code I have is wrong. If the data frame has 15 columns I want 15 cvs columns.
Here is what I am doing:
t= None
for i in range(len(VF.columns)):
t= pd.Dataframe(VF[i])
t.to_csv()
I am using jupyter notebook. Could anybody explain what's happening in the code given above?
3 Answers
3
If I'm understanding correctly, you can try:
for col in VF.columns:
VF[[col]].to_csv('%s.csv' % col)
Why not just use:
for i in range(len(VF.columns)):
VF.columns[i].to_csv()
No need to store it as a separate dataframe
Also your loop needs the ".columns" on the VF for iterating i. Otherwise your grabbing all columns for each row.
I think that this what you want
List = np.arange(0,15,1)
for i in List:
i.to_csv('location-of -file/i.csv')
List = np.arange(0,15,1)
for i in List:
i.to_csv('location-of -file/i.csv')
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I did but I am computer was a bit slow so I could not see the files instantly. Nice one anyway
– Herc01
Sep 2 at 17:58