KnowledgeBoat Logo
|
LoginJOIN NOW

Informatics Practices

How can we import specific columns from a CSV file?

Python Data Handling

1 Like

Answer

To import specific columns from a CSV file, we can use the usecols parameter of the read_csv function from the pandas library. The usecols parameter is used to specify the list of columns to be read from the CSV file. The syntax is pd.read_csv('filename.csv', usecols = ['column1', 'column2',...]).

For example, the following command will access Name and Age columns of Employee file.

df = pd.read_csv("Employee.csv", usecols = ['Name', 'Age'])
print(df)

Answered By

3 Likes


Related Questions