Import a CSV file
Write a pandas program to import a CSV file.
name age city 0 Asha 29 Pune 1 Ravi 31 Delhi (2, 3)
Approach
pd.read_csv.
Solution
import pandas as pdwith open("people.csv", "w") as f: f.write("name,age,city\nAsha,29,Pune\nRavi,31,Delhi\n")df = pd.read_csv("people.csv")print(df)print(df.shape)name age city 0 Asha 29 Pune 1 Ravi 31 Delhi (2, 3)
Line by line
Creates a sample file so the program runs anywhere.
Learn the concept
New to this topic? Read the lesson, then come back.