Pandas, How to read a CSV file


df = pd.read_csv('input.csv', 
                    usecols=[0, 2, 3])

Pandas reads the content of of CSV file using the read_csv method and the file name. The index column and the column used are optional parameters.


This code example imports the Pandas library, loads the content of the file called input.csv. The index column is column A and the system only imports the first 3rd and 4th columns. The dataframe loaded is then written in the output.

import pandas as pd 

df = pd.read_csv('input.csv', 
                    usecols=[0, 2, 3])

print( df )

The output will be:

     C   D
1    3   4
5    7   8
9   11  12
13  15  16
17  19  20


Pandas CSV

Recent Comments