Skip to main contentSkip to solution

While transferring the data from a DataFrame to CSV file, if we do not want the column names to be saved to the file on the disk, the parameter to be used in to_csv() is_________.

Solution

✅ Correct Option: 1

The to_csv() method of a pandas DataFrame has a header parameter that controls whether the column names are written to the file. Setting header=False leaves them out, and the default is header=True.

For example, df.to_csv('data.csv', header=False) saves only the data rows, with no column names.


Option 2: index=False stops the row index from being written. It does not affect the column names.

Option 3: header=True is the default, so the column names would still be saved.

Option 4: index=True is also the default and only keeps the row labels in the file.

header controls the column names and index controls the row labels. Students often mix these two up.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question