Can I use column names?

0200

Yes, you can use column names with the index_col parameter in the read_csv function. You can specify the name of the column you want to use as the index directly.

For example:

import pandas as pd

# Using a column named 'Name' as the index
df = pd.read_csv('data.csv', index_col='Name')

You can also use a list of column names if you want to create a multi-index:

df = pd.read_csv('data.csv', index_col=['Name', 'Age'])  # Using 'Name' and 'Age' as a multi-index

This allows you to set meaningful indices based on the data in your CSV file.

0 Comments

no data
Be the first to share your comment!