Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using pandas in python to read a csv,how do I pass a sheet name to read particular sheet

Tags:

python

pandas

csv

I am using pandas in python to read a .csv file ,how do I pass a sheet name to the function pandas.read_csv() so I can read data from a particular sheet. The code used is :

import pandas as pd 
pd.read_csv("filename.csv") 

How do I pass the sheet name as an argument?????

like image 221
vasu sharma Avatar asked Mar 16 '20 04:03

vasu sharma


People also ask

When a .CSV file is read with pandas read_csv () what is returned by this function?

A comma-separated values (csv) file is returned as two-dimensional data structure with labeled axes. Write DataFrame to a comma-separated values (csv) file. Read a comma-separated values (csv) file into DataFrame.


1 Answers

CSV file is as comma seperated file and so there is no concept of multiple sheets. Try

pd.read_excel('path_to_file.xls', sheetname='Sheet1')

Following link might help.

like image 95
Sharan Avatar answered Oct 16 '22 20:10

Sharan