import csv in dataframe and take the first column as index in python

main.py
import pandas as pd

df = pd.read_csv('file.csv', index_col=0)
63 chars
4 lines

In this snippet, we import the pandas library as pd. Then we use the read_csv() method to read the csv file named 'file.csv' into a pandas DataFrame. We use the index_col parameter to specify that we want the first column of the CSV to be used as the index of the DataFrame. The resulting DataFrame is stored in the variable df.

gistlibby LogSnag