Python Practice › Pandas Programs › Program 94

Import a CSV file

EasyPandas Programs · 94 of 95

Write a pandas program to import a CSV file.

Advertisement
Output
   name  age   city
0  Asha   29   Pune
1  Ravi   31  Delhi
(2, 3)

Approach

  1. pd.read_csv.

Solution

Python
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)
Output
   name  age   city
0  Asha   29   Pune
1  Ravi   31  Delhi
(2, 3)

Line by line

Lines 2-3

Creates a sample file so the program runs anywhere.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs