Append a Header for CSV file?

后端 未结 6 683
后悔当初
后悔当初 2020-12-25 07:59

I am trying to add a header to my CSV file.

I am importing data from a .csv file which has two columns of data, each containing float numbers. Example:



        
6条回答
  •  时光取名叫无心
    2020-12-25 08:42

    For the issue where the first row of the CSV file gets replaced by the header, we need to add an option.

    import pandas as pd  
    df = pd.read_csv('file.csv', **header=None**)  
    df.to_csv('file.csv', header = ['col1', 'col2']) 
    

提交回复
热议问题