How to add header row to a pandas DataFrame

后端 未结 4 2057
梦谈多话
梦谈多话 2020-11-28 17:54

I am reading a csv file into pandas. This csv file constists of four columns and some rows, but does not have a header row, which I want to add. I have been try

4条回答
  •  醉酒成梦
    2020-11-28 18:48

    To fix your code you can simply change [Cov] to Cov.values, the first parameter of pd.DataFrame will become a multi-dimensional numpy array:

    Cov = pd.read_csv("path/to/file.txt", sep='\t')
    Frame=pd.DataFrame(Cov.values, columns = ["Sequence", "Start", "End", "Coverage"])
    Frame.to_csv("path/to/file.txt", sep='\t')
    

    But the smartest solution still is use pd.read_excel with header=None and names=columns_list.

提交回复
热议问题