python玩转大数据-数据选择

# coding=utf-8
from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date
from datetime import datetime
import pandas as pd
today = date.today()
start = (today.year-1,today.month,today.day)
quotes = quotes_historical_yahoo_ochl('AXP', start, today)
fields = ['date','open','close','high','low','column']
list1 = []
for i in range(0,len(quotes)):
    x = date.fromordinal(int(quotes[i][0]))
    y = datetime.strftime(x,'%Y-%m-%d')
    list1.append(y)
df = pd.DataFrame(quotes,index=list1,columns = fields)
df = df.drop(['date'],axis=1)
print df.tail(5),df.head(5)
print df[u'2015-12-02':u'2015-12-20']
print df.loc[:,['open','low']]
print df.iloc[1,2]
print df[(df.index >= u'2014-01-01') & (df.close >= 80)]

 

转载于:https://my.oschina.net/passer007/blog/680956

你可能感兴趣的:(python玩转大数据-数据选择)