How to read multiple columns from CSV file in Python

You can read multiple columns from CSV file in Python with the following code. I highly recommend you This book to learn Python.

Read multiple columns

# Import the Pandas library as pd
import pandas as pd

# Select columns which you want to read
columns = ["Area", "Price"]

# Read specific columns from CSV file
df = pd.read_csv("house_price.csv", usecols=columns)

print(df)

Output:

   Area  Price
0  5000  75000
1  4000  65000
2  3000  60000
3  2000  58000
4  1500  50000
5  7000  90000
6  6000  85000
7  6500  80000
8  8000  95000

Free Learning Resources

Leave a Comment

Your email address will not be published.