Skip to main contentSkip to solution

Which of the following function is used to read from a 'csv' file into a pandas ('pd' as alias) DataFrame?

Solution

✅ Correct Option: 3

pd.read_csv() reads a CSV file and returns a pandas DataFrame. For example, df = pd.read_csv("data.csv") loads the file into df.


Option 4: to_csv() does the opposite job. It is a DataFrame method that writes data out to a CSV file, as in df.to_csv("out.csv").

Options 1 and 2: load_csv() and write_csv() do not exist in pandas.

The pandas pattern is read_xxx() to import, as in read_excel() and read_json(), and to_xxx() to export.

Keyboard Shortcuts

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