Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accessing data on the web and in the cloud


It is quite common to read data off the web and from the cloud. pandas makes it extremely easy to read data from the web and cloud. All of the pandas functions we have examined can also be given an HTTP URL, FTP address, or S3 address instead of a local file path, and all work just the same as they work with a local file.

The following demonstrates how easy it is to directly make HTTP requests using the existing pd.read_csv() function. The following retrieves the daily stock data for Microsoft in June 2014 directly from the Yahoo! Finance web service via its HTTP query string model:

In [32]:
   # read csv directly from Yahoo! Finance from a URL
   df = pd.read_csv("http://ichart.yahoo.com/table.csv?s=MSFT&" +
                    "a=5&b=1&c=2014&" +
                    "d=5&e=30&f=2014&" +
                    "g=d&ignore=.csv")
   df[:5]

Out[32]:
            Date   Open   High    Low  Close    Volume  Adj Close
  ...