Adding the header to a csv file

后端 未结 4 1261
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 20:21

I have a csv file with the dimensions 100*512 , I want to process it further in spark. The problem with the file is that it doesn\'t contain header i.e

4条回答
  •  不要未来只要你来
    2021-01-26 20:31

    First read your csv file:

    from pandas import read_csv      
    df = read_csv('test.csv')
    

    If there are two columns in your dataset(column a, and column b) use:

    df.columns = ['a', 'b']
    

    Write this new dataframe to csv

    df.to_csv('test_2.csv')
    

提交回复
热议问题