Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a CSV file from a URL with Python?

when I do curl to a API call link http://example.com/passkey=wedsmdjsjmdd

curl 'http://example.com/passkey=wedsmdjsjmdd' 

I get the employee output data on a csv file format, like:

"Steve","421","0","421","2","","","","","","","","","421","0","421","2" 

how can parse through this using python.

I tried:

import csv  cr = csv.reader(open('http://example.com/passkey=wedsmdjsjmdd',"rb")) for row in cr:     print row 

but it didn't work and I got an error

http://example.com/passkey=wedsmdjsjmdd No such file or directory:

Thanks!

like image 676
mongotop Avatar asked Apr 29 '13 16:04

mongotop


People also ask

How do I read a CSV file from a website in Python?

Use the pandas. read_csv() Function to Download a CSV File From a URL in Python. The read_csv() function from the Pandas module can read CSV files from different sources and store the result in a Pandas DataFrame.

How do I extract a CSV file from a website?

Expor websites to CSV There is no simple solution to export a website to a CSV file. The only way to achieve this is by using a web scraping setup and some automation. A web crawling setup will have to be programmed to visit the source websites, fetch the required data from the sites and save it to a dump file.


1 Answers

Using pandas it is very simple to read a csv file directly from a url

import pandas as pd data = pd.read_csv('https://example.com/passkey=wedsmdjsjmdd') 

This will read your data in tabular format, which will be very easy to process

like image 51
Kathirmani Sukumar Avatar answered Sep 16 '22 23:09

Kathirmani Sukumar