갈루아의 반서재

728x90

ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#-*- coding: utf-8 -*-
 
import pandas as pd
import pandas.io.data as web
import datetime
 
def download_stock_data(file_name, company_code, year1, month1, date1, year2, month2, date2):
    start = datetime.datetime(year1, month1, date1)
    end = datetime.datetime(year2, month2, date2)
    df = web.DataReader("%s.KS" % (company_code), "yahoo", start, end)
    
    df.to_pickle(file_name)
    
    return df
 
download_stock_date('samsung.data''005930'20161120161)
 
cs


ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.


pandas-datareader 패키지를 설치한다.

1
$ pip install pandas-datareader
cs


ln[4] 와 같이 임포트한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#-*- coding: utf-8 -*-
 
import pandas as pd
import pandas_datareader.data as web
import datetime
 
def download_stock_data(file_name, company_code, year1, month1, date1, year2, month2, date2):
    start = datetime.datetime(year1, month1, date1)
    end = datetime.datetime(year2, month2, date2)
    df = web.DataReader("%s.KS" % (company_code), "yahoo", start, end)
    
    df.to_pickle(file_name)
    
    return df
 
download_stock_data('samsung.data''005930'201610120161031)
cs


실행결과


Open

High

Low

Close

Volume

Adj Close

Date







2016-10-03

1598000.0

1598000.0

1598000.0

1598000.0

0

1598000.0

2016-10-04

1610000.0

1624000.0

1606000.0

1614000.0

261000

1614000.0

2016-10-05

1601000.0

1626000.0

1597000.0

1619000.0

249400

1619000.0

2016-10-06

1696000.0

1700000.0

1667000.0

1691000.0

591100

1691000.0

2016-10-07

1700000.0

1716000.0

1690000.0

1706000.0

521000

1706000.0

2016-10-10

1650000.0

1689000.0

1628000.0

1680000.0

505800

1680000.0

2016-10-11

1600000.0

1625000.0

1545000.0

1545000.0

768500

1545000.0

2016-10-12

1495000.0

1545000.0

1494000.0

1535000.0

781700

1535000.0

2016-10-13

1550000.0

1581000.0

1545000.0

1557000.0

437200

1557000.0

2016-10-14

1548000.0

1588000.0

1547000.0

1577000.0

283100

1577000.0

2016-10-17

1565000.0

1602000.0

1538000.0

1590000.0

255700

1590000.0

2016-10-18

1572000.0

1595000.0

1572000.0

1589000.0

207600

1589000.0

2016-10-19

1579000.0

1643000.0

1575000.0

1625000.0

308800

1625000.0

2016-10-20

1626000.0

1651000.0

1609000.0

1620000.0

206600

1620000.0

2016-10-21

1606000.0

1613000.0

1588000.0

1589000.0

209500

1589000.0

2016-10-24

1593000.0

1608000.0

1590000.0

1608000.0

185700

1608000.0

2016-10-25

1600000.0

1604000.0

1592000.0

1597000.0

197300

1597000.0

2016-10-26

1597000.0

1599000.0

1562000.0

1567000.0

210600

1567000.0

2016-10-27

1571000.0

1617000.0

1556000.0

1573000.0

282300

1573000.0

2016-10-28

1580000.0

1614000.0

1580000.0

1614000.0

204200

1614000.0

2016-10-31

1616000.0

1639000.0

1611000.0

1639000.0

241300

1639000.0


728x90