📅  最后修改于: 2023-12-03 15:33:23.877000             🧑  作者: Mango
Sometimes, when working with pandas dataframe, we might want to save the dataframe as a CSV file without the header. There are several ways to do it using pandas.
One way is to set the header parameter of the to_csv method to False, like this:
import pandas as pd
df = pd.DataFrame({'Column1': [1, 2, 3], 'Column2': [4, 5, 6], 'Column3': [7, 8, 9]})
df.to_csv('filename.csv', header=False)
This will save the dataframe as a CSV file without the header.
Another way to achieve this is by using the DataFrame.to_csv method with the line_terminator parameter set to an empty string:
df.to_csv('filename.csv', header=False, line_terminator='')
This will save the dataframe as a CSV file without the header and with no line terminator.
In both cases, the resulting CSV file will not have a header row.
Markdown:
Sometimes, when working with pandas dataframe, we might want to save the dataframe as a CSV file without the header. There are several ways to do it using pandas.
One way is to set the header
parameter of the to_csv
method to False
, like this:
import pandas as pd
df = pd.DataFrame({'Column1': [1, 2, 3], 'Column2': [4, 5, 6], 'Column3': [7, 8, 9]})
df.to_csv('filename.csv', header=False)
This will save the dataframe as a CSV file without the header.
Another way to achieve this is by using the DataFrame.to_csv
method with the line_terminator
parameter set to an empty string:
df.to_csv('filename.csv', header=False, line_terminator='')
This will save the dataframe as a CSV file without the header and with no line terminator.
In both cases, the resulting CSV file will not have a header row.