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)
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
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.
Related questions:
2025: 21 May Shift 1
2025: 15 May Shift 2