Home > Software engineering >  Attempting to add a column heading to the newly created csv file
Attempting to add a column heading to the newly created csv file

Time:01-03

I'm trying to add the add the header to my csv file that I created in the code given below: This is the code im using

There's only 1 column in the csv file that I'm trying to create, the data frame consists of an array, the array is [0.6999346, 0.6599296, 0.69770324, 0.71822715, 0.68585426, 0.6738229, 0.70231324, 0.693281, 0.7101939, 0.69629824] i just want to create a csv file with header like this

Desired csv File , I want my csv file in this format

enter image description here

Please help me with detailed code, I'm new to coding.

I tried this

df = pd.DataFrame(c)
df.columns = ['Confidence values']
pd.DataFrame(c).to_csv('/Users/sunny/Desktop/objectdet/final.csv',header= True , index= True)

Im getting this

But i'm getting this csv file

CodePudding user response:

Try this

import pandas as pd
array = [0.6999346, 0.6599296, 0.69770324, 0.71822715, 0.68585426, 0.6738229, 0.70231324, 0.693281, 0.7101939, 0.69629824]
df = pd.DataFrame(array)
df.columns = ['Confidence values']
df.to_csv('final.csv', index=True, header=True)

CodePudding user response:

df.to_csv('/Users/sunny/Desktop/objectdet/final.csv',header= True , index= True)
  • Related