Monday, April 24, 2017

How to read tabular data using pandas


Tabular data are data that looks like a table. Data with rows and columns like excel spreadsheet.common format is tabular data




1) Need to import panda
import panda as pd

2) Read table
 by default read_table assumes that the dataset is tab seperated.
pd.read_table('http://bit.ly/chiporders')

3) Run a dataset
  • By default it would add the header
  • It added the index on the left side

Delimiters

If the delimiters is other than tab then we need to specify the delimiter
pd.read_table('http://bit.ly/movieusers',sep='|',header=None)

Note : we can save it as an object
user_cols =['user_id','age','gender','occupation','zip_code']
users=pd.read_table('http://bit.ly/movieusers', sep='|',header=None,names=user_cols)

No comments:

Post a Comment