Monday, April 17, 2017

Python Pandas - Read CSV file from URL Example

Here is an example on how to read CSV file from URL.
Census data used as source.

Use Case : Read Population data for state of California from "censusdata.ire.org" URL and display the data.

Syntax : 


pandas.read_csv(URL)

Main Parameters :


Separator or delimiter : 
  • sep='|' 
  • delimiter='|'
  • default ‘,’

header :
  • header='infer'
  • default ‘infer’'

usecols :
  • For subset of columns
  • usecols=None

skiprows :
  • Number of lines to skip at the start
  • default 0

skipfooter :
  • Number of lines to skip at the bottom
  • default 0

Sample Code

#################
# Sample Code
#################
import pandas as pd
df = pd.read_csv("http://censusdata.ire.org/06/all_050_in_06.P1.csv")
df.head(5)


Sample Output






No comments:

Post a Comment