A data frame can be created by reading data from a CSV file using the pd.read_csv() function.
To demonstrate this process, we will load data from a file that contains a snapshot of the S&P 500. This file is named sp500.csv and is located in the code bundle's data directory.
The first line of the file has the names of each variable/column, and the remaining 500 lines represent the values for the 500 different stocks.
The following code loads the data, while specifying which column in the file to use for the index and also that we only want four specific columns (0, 2, 3, and 7):
Examining the first five rows using .head() shows ...