To import a CSV file as a Pandas DataFrame, the solution is quite simple. Pandas provides a convenient read_csv function that takes care of this task.
import pandas as pd
To read the given CSV file into a DataFrame, use the read_csv function:
df = pd.read_csv("data.csv")
Once the data is read, you can print the DataFrame to view its contents:
print(df)
This will output the CSV data as a DataFrame with the following columns:
And their corresponding values. Here's an example output:
Date price factor_1 factor_2 0 2012-06-11 1600.20 1.255 1.548 1 2012-06-12 1610.02 1.258 1.554 2 2012-06-13 1618.07 1.249 1.552 3 2012-06-14 1624.40 1.253 1.556 4 2012-06-15 1626.15 1.258 1.552 5 2012-06-16 1626.15 1.263 1.558 6 2012-06-17 1626.15 1.264 1.572
The above is the detailed content of How Can I Import a CSV File into a Pandas DataFrame?. For more information, please follow other related articles on the PHP Chinese website!