Skip to main contentSkip to solution

To read the data from the CSV file in order to create DataFrame, ______ is the correct function. (Assume 'df' is the name of the DataFrame)

Solution

✅ Correct Option: 1

pandas.read_csv() is the function that reads a CSV file and returns a DataFrame, for example df = pandas.read_csv("data.csv"). It is a function of the pandas module, so it is called through the module name (usually pd.read_csv() after import pandas as pd).


Option 2: to_csv() does the opposite job. It writes an existing DataFrame out to a CSV file, as in df.to_csv("out.csv").

Option 3: pandas.read.csv() is invalid syntax. The function name is a single word with an underscore, read_csv.

Option 4: read_csv() is not a DataFrame method. df does not exist until read_csv() creates it.

Keyboard Shortcuts

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