本文整理汇总了Python中pandas.io.data.DataReader.applymap方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.applymap方法的具体用法?Python DataReader.applymap怎么用?Python DataReader.applymap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.data.DataReader
的用法示例。
在下文中一共展示了DataReader.applymap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DataReader
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import applymap [as 别名]
start=dt.datetime(2007, 01, 01)
end=dt.date.today()
LI3=pd.date_range(start, end, freq='D')
curr=['USD','GBP','EUR']
libor_1m=[]
for i in curr:
tick=i+'1MTD156N'
libor_1m.append(tick)
df_libor_1m=pd.DataFrame(index=LI3)
for i in libor_1m:
df2 = DataReader(i, "fred", start,end)
df2=df2.applymap(f)
df2=df2.ffill()
df_libor_1m[i]=df2
df_libor_1m=df_libor_1m.ffill()
df_libor_1m.columns=curr
print df_libor_1m.head(8)
libor_1w=[]
for i in curr:
tick=i+'1WKD156N'
libor_1w.append(tick)
df_libor_1w=pd.DataFrame(index=LI3)
for i in libor_1w:
df2 = DataReader(i, "fred", start,end)
示例2: float
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import applymap [as 别名]
from pandas.io.data import DataReader
from datetime import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
randn = np.random.randn
f = lambda x: float(x)
SPX = DataReader("SP500", "fred", datetime(2013,1,1), datetime(2013,05,05) ) #SPX
SPX=SPX['SP500'].replace('.',np.nan).fillna(method='ffill')
SPX=pd.DataFrame(SPX)
SPX=SPX.applymap(f)
#dr = pd.date_range('1/1/2013', periods=20, freq=3 * pd.datetools.bday)
start = datetime(2013, 1, 1)
end = datetime(2013, 5, 11)
#startrng = pd.bdate_range(start,end,freq='BQS-MAR')
#startrng = pd.bdate_range(start,end,freq='BMS') #first business day of month
startrng = pd.bdate_range(start,end,freq='WOM-2TUE') #second Tuesday of month
#startrng = startrng + pd.datetools.WeekOfMonth(week=1,weekday=4) - pd.datetools.BDay()
print startrng
SPX=SPX.reindex(startrng)
print SPX
示例3: get_data
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import applymap [as 别名]
def get_data(start,end,sec):
fl = lambda x: float(x)
data = DataReader(sec, "yahoo", start,end)
data=data.applymap(fl)
data=data.ffill()
return data
示例4: float
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import applymap [as 别名]
# Parameters---------------------------------------------------------
database='test'
table='sp500'
start=dt.datetime(2012, 01, 01)
end=dt.datetime.today()
LI3=pd.date_range(start, end, freq='D')
#functions--------------------
f = lambda x: float(x)
df = DataReader('SP500', "fred", start,end)
df=df.applymap(f)
#calculate average per year
annual_df = df.resample('M', how='mean')
print annual_df.to_string()
#calculate return index
df['ret'] = df['SP500'].pct_change()
df=df.reindex(columns=['SP500','ret'])
df['ri'] = (1 + df['ret']).cumprod()
# calculate monthly returns
m_returns = df['ri'].resample('BM', how='last').pct_change()
print m_returns
# turn business day into full days