Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am trying to export my data frame to the CSV file. I had 2 columns but when I export it to CSV, I am left out with only one column. The data format is in a comma-separated way.

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

To append the values in the new data frame I used the below code:

with open('test.csv', 'a+') as f:        

    df.to_csv(f, header=False)    

print(df)

I am getting the output looks like:

    MSE      SSIM  

0  0.743373  0.843658

When I go back and check the CSV file I can see the file in this format:

0,1.1264238582283046,0.8178900901529639

How can I solve this?

1 Answer

0 votes
by (36.8k points)

When you are extracting the CSV file you need to use the below format of code:

df.to_csv(f, header=False, sep=';') 

Hear sep is  separate by ';'

If you are a beginner and want to know more about Data Science the do check out the Data Science course

Browse Categories

...