Download and access data from gythub python

Hi, I was going through Python analysis to analyze the data, and I would like to analyze the data that it views in the book. In chapter 9, he uses the data below. However, it's hard for me to figure out how to use the data in my ipython laptop as soon as I upload it to the github app on mac.

Stock data is here: https://github.com/pydata/pydata-book/blob/master/ch09/stock_px.csv

I hit open, which uploaded a large file to my github app. This is as follows. How can I open this data in my ipython laptop?

** Looking at other stackoverflow related issues, I know that I can just download the zip file, which I also do. It would be great to know how to make good use of the github app.

Right click and save the csv file, it seems save the json / html file

enter image description here

+4
source share
1 answer

You can simply use the urlraw version (the link to the raw version is the button on the link you specified) and then read it in the dataframe directly with read_csv:

import pandas as pd
url = 'https://raw.githubusercontent.com/pydata/pydata-book/master/ch09/stock_px.csv'
df = pd.read_csv(url,index_col=0,parse_dates=[0])

print df.head(5)

            AAPL   MSFT    XOM     SPX
2003-01-02  7.40  21.11  29.22  909.03
2003-01-03  7.45  21.14  29.24  908.59
2003-01-06  7.45  21.52  29.96  929.01
2003-01-07  7.43  21.93  28.95  922.93
2003-01-08  7.28  21.31  28.83  909.93

Edit: A brief description of the options I used to read in the file:

df = pd.read_csv(url,index_col=0,parse_dates=[0])

( = 0) , , , ; index_col=0 parse_dates [0] read_csv = 0 ( ) .

+6

Source: https://habr.com/ru/post/1539207/


All Articles