pythonpandas

How to hide or remove all headers from a pandas DataFrame


I want to delete to just column name (x,y,z), and display only the data.

In [68]: df
Out[68]: 
   x  y  z
0  1  0  1  
1  2  0  0 
2  2  1  1 
3  2  0  1 
4  2  1  0

I want to print result to same as below.

Out[68]: 

0  1  0  1  
1  2  0  0 
2  2  1  1 
3  2  0  1 
4  2  1  0

Is it possible? How can I do this?


Solution

  • In pandas by default need column names.

    But if really want 'remove' columns what is strongly not recommended, because get duplicated column names is possible assign empty strings:

    df.columns = [''] * len(df.columns)
    

    But if need write df to file without columns and index add parameter header=False and index=False to to_csv or to_excel.

    df.to_csv('file.csv', header=False, index=False)
    
    df.to_excel('file.xlsx', header=False, index=False)