Removing header column from pandas dataframe

前端 未结 4 631
眼角桃花
眼角桃花 2020-12-09 08:46

I have the foll. dataframe:

df

   A   B
0  23  12
1  21  44
2  98  21

How do I remove the column names A and B

4条回答
  •  盖世英雄少女心
    2020-12-09 09:06

    How to get rid of a header(first row) and an index(first column).

    To write to CSV file:

    df = pandas.DataFrame(your_array)
    df.to_csv('your_array.csv', header=False, index=False)
    

    To read from CSV file:

    df = pandas.read_csv('your_array.csv')
    a = df.values
    

    If you want to read a CSV file that doesn't contain a header, pass additional parameter header:

    df = pandas.read_csv('your_array.csv', header=None)
    

提交回复
热议问题