1

I want to export my dataframe to a csv file. normally I want my dataframe as 2 columns but when I export it, in csv file there is only one column and the data is separated with comma.

m is one column and s is another.

df = pd.DataFrame({'MSE':[m], 'SSIM': [s]})

to append new data frames I used below function and save data to csv file:.

with open('test.csv', 'a+') as f:        
    df.to_csv(f, header=False)    

print(df)

when I print dataframe on console output looks like:

    MSE      SSIM  

0  0.743373  0.843658

but in csv file a column looks like: here first is index, second is m and last one is s. I want them in 3 seperate columns

0,1.1264238582283046,0.8178900901529639

How can I solve this?

4
  • A single column in what? When opened in Excel? Commented Jul 10, 2018 at 19:28
  • Can we see what the data looks like? Can't really help without seeing any more info Commented Jul 10, 2018 at 19:28
  • @roganjosh Yes, in excel file in a single row all my data is in a single column. I want them to be in 3 seperate columns. Commented Jul 10, 2018 at 19:36
  • I suspect that it's an issue with excel because there doesn't appear to be an issue with the approach. Otherwise I think you'll need to post a reproducible example for us to be able to move forward. Commented Jul 10, 2018 at 19:38

1 Answer 1

1

Your excel setting is most likely ; (semi-colon). Use:

df.to_csv(f, header=False, sep=';') 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.