Execute the following steps to load a dataset into Python.
- Import the libraries:
import pandas as pd
- Preview a CSV file:
!head -n 5 credit_card_default.csv
The output looks like this:
- Load the data from the CSV file:
df = pd.read_csv('credit_card_default.csv', index_col=0,
na_values='')
The DataFrame has 30,000 rows and 24 columns.
- Separate the features from the target:
X = df.copy()
y = X.pop('default_payment_next_month')
After running this block of code, X no longer contains the target column.