当前位置: 首页>>代码示例>>Python>>正文


Python DataReader.rename方法代码示例

本文整理汇总了Python中pandas.io.data.DataReader.rename方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.rename方法的具体用法?Python DataReader.rename怎么用?Python DataReader.rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.io.data.DataReader的用法示例。


在下文中一共展示了DataReader.rename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_ohlc

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
def download_ohlc(sector_tickers, start, end):
    sector_ohlc = {}
    for sector, tickers in sector_tickers.iteritems():
        print 'Downloading data from Yahoo for %s sector' % sector
        data = DataReader(tickers, 'yahoo', start, end)
        for item in ['Open', 'High', 'Low']:
            data[item] = data[item] * data['Adj Close'] / data['Close']
        data.rename(items={'Open': 'open', 'High': 'high', 'Low': 'low',
                           'Adj Close': 'close', 'Volume': 'volume'},
                    inplace=True)
        data.drop(['Close'], inplace=True)
        sector_ohlc[sector] = data
    print 'Finished downloading data'
    return sector_ohlc
开发者ID:Allen1203,项目名称:pyktrader,代码行数:16,代码来源:test_data.py

示例2: ts

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
    def ts(self, symbol):
        parse = self.parsesymbol(symbol)
        df    = DataReader(parse['eq'], parse['proto'],start=datetime.datetime(1950,1,1))
        df    = df.rename(columns=lambda x: '_'.join(x.split()).lower()) # Need for Adj Close :(
        #print df.columns
        ts = df[parse['hlocv']]
        ts.index = map(lambda x: x.date(), ts.index)
        ts.name  = parse['eq']
        if '@' in symbol:
	    ts.name += '@%s' % (parse['hlocv'])
        return ts
开发者ID:waldenven,项目名称:tsdata,代码行数:13,代码来源:pandasdata.py

示例3: import_data_yahoo_to_files

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
def import_data_yahoo_to_files( list_symbols,path,startdate):       
        list_error=[]
        logger.info("importing from "+str(startdate))    
        for symbol in  list_symbols:
            try :                
                    prices_df = DataReader(symbol, "yahoo", startdate)                
                    count_newdata = len(prices_df)
                    print  symbol , " ", count_newdata     
                    if(count_newdata <=0):
                        raise Exception("NO DATA for Dates for %s"%symbol)           
                    prices_df = prices_df.rename(columns={'Date': 'date', 'Open': 'open', 'High': 'high',
                                                   'Low': 'low', 'Close': 'actualclose', 'Adj Close': 'close',
                                                   'Volume': 'volume', 'Symbol': 'symbol'})
                    prices_df['symbol'] = symbol             
                    prices_df['symbol'] = prices_df.apply(lambda x: x['symbol'].replace('\r','').upper(), axis=1 )    
                    prices_df.to_csv(path + "/" + symbol + '.csv')                    
            except Exception as ex:
                logger.error(ex)
                list_error.append(symbol)
                logger.error(traceback.format_exc())
开发者ID:vinodnayal,项目名称:iview,代码行数:22,代码来源:dataimport.py

示例4: DataReader

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
cat = df['subcat']
t = df[(cat == 22.0) | (cat == 24.0) | (cat == 25.0)]
# To adjust for population
try:
    popn = DataReader('CNP16OV', data_source='fred', start='1970')
    popn = popn.resample('A')
    gdp = DataReader('GDPC1', data_source='fred',
                     start='1974').resample('A')
except IOError:
    print('No Connection.')

patents = df.groupby('appyear')['patent'].count().ix[1975:2002]
gdp = gdp.ix['1975':'2002']
patents.index = gdp.index
gdp['patents'] = patents
gdp.rename(columns={'GDPC1': 'gdp'})
fig = plt.figure()
ax = fig.add_subplot(111)
ax = gdp.plot(ax=ax, secondary_y=['patents'], grid=True)
ax.set_ylabel('Billions of Chained 2005 Dollars')
ax.set_xlabel('')
plt.savefig('gdp_app_all.png', dpi=300)

patents = t.groupby('appyear')['patent'].count().ix[1975:2002]
gdp = gdp.ix['1975':'2002']
patents.index = gdp.index
gdp['patents'] = patents
gdp.rename(columns={'GDPC1': 'gdp'})
fig = plt.figure()
ax = fig.add_subplot(111)
ax = gdp.plot(ax=ax, secondary_y=['patents'], grid=True)
开发者ID:TomAugspurger,项目名称:software,代码行数:33,代码来源:gdp_app_comparison.py

示例5: DataReader

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
import matplotlib.pyplot as plt
from datetime import datetime
from pandas.io.data import DataReader

code_names = {
    '005930.KS':'Samsung Elec', '005380.KS':'Hyundai Motor','000660.KS':'SK Hynix', '015760.KS':'kor elect',
    '012330.KS':'Hyundai Mobis', '005490.KS':'POSCO', '017670.KS':'SK tele','^KS11':'KOSPI',
    '035420.KS':'NAVER','055550.KS':'sinhan','032830.KS':'samsung life', '000270.KS':'Kia', '090430.KS':'AmoreF',
    '090430.KS':'LG chemi','105560.KS':'KB','000810.KS':'samsung fire', '034220.KS':'LG display', '033780.KS':'KT&G',
    '051900.KS':'LG health','003550.KS':'LG','034730.KS':'SK cnc', '066570.KS':'LG elec', '002790.KS':'AmoreG',
    '009540.KS':'Samsung shi','006400.KS':'Samsung SDI','086280.KS':'Hy globis', '096770.KS':'SK ino', '000830.KS':'Samsung c&t'}

df = DataReader(code_names.keys(), 'yahoo', start='2014-03-01', end='2015-02-28')

df = df['Adj Close']
df = df.rename(columns=code_names)

changes = df.pct_change()
chg_corr = changes.corr()
chg_corr

plt.figure(figsize=(16,8))
plt.scatter(changes.mean(), changes.std())
plt.xlabel('returns')
plt.ylabel('risk')

for label, x, y in zip(changes.columns, changes.mean(), changes.std()):
    plt.annotate( label,xy=(x, y), xytext=(30, -30),
                  textcoords = 'offset points', ha = 'right', va = 'bottom',
                  bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
                  arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
开发者ID:aq2814,项目名称:testanything,代码行数:33,代码来源:kospi2015+(1).py

示例6: dict

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
# <codecell>

series = dict(jobs = "PAYEMS",
              income = "PI",
              prod = "INDPRO",
              cons = "PCEC96",
              prices = "CPIAUCSL")

# <codecell>

try:
    indicators = []
    for variable in series:
        data = DataReader(series[variable], "fred", start="2000-10-1")
        data.rename(columns={series[variable] : variable}, inplace=True)
        indicators.append(data)
    indicators = pandas.concat(indicators, axis=1)
    indicators.to_csv("/home/skipper/school/talks/538model/tmp_indicators_full.csv")
except: # probably not online
    indicators = pandas.read_csv("/home/skipper/school/talks/538model/tmp_indicators_full.csv", 
                                 parse_dates=True)
    indicators.set_index("DATE", inplace=True)
    # why doesn't it do this automaticall?
    indicators.index = pandas.DatetimeIndex(indicators.index)

# <markdowncell>

# For stock variables, just compute annualized quarterly growth rates (end - beginning)/beginning * 400 and average.

# <codecell>
开发者ID:Aran00,项目名称:538model-fork,代码行数:32,代码来源:historical_adjustment.py

示例7: Equity

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
class Equity(object):
    """
    An Equity object provides an interface to Share Price Data for a specified Ticker Code.

    It uses pandas (DataReader and DataFrame) and SQLite as a local data store.

    Use importData() to update the SQLite data from Yahoo (adjusting as necessary) and use dataFrame() to get at the
    adjusted data.
    """

    def __init__(self, tickerCode):
        """
        Constructor.

        There isn't much to see here. It just makes a note of the Ticker Code.

        :param tickerCode: Ticker Code.
        """

        Logger.log(logging.DEBUG, "Log Object Creation", {"scope":__name__, "arguments":" ".join({tickerCode})})

        self._tickerCode = tickerCode


    def importData(self):
        """
        Import (New) Data from Yahoo.
        """

        start = self._getLatestDate()
        end = self._getTodaysDate()

        Logger.log(logging.INFO, "Loading Data", {"scope":__name__, "tickerCode":self._tickerCode, "start":str(start), "end":str(end)})
        self._data = DataReader(self._tickerCode, "yahoo", start, end)

        self._data['Code'] = self._tickerCode

        for item in ['Open', 'High', 'Low']:
            self._data[item] = self._data[item] * self._data['Adj Close'] / self._data['Close']

        self._data.drop('Close', axis=1, inplace=True)
        self._data.rename(columns={'Adj Close':'Close'}, inplace=True)
        self._data['Volume'] = self._data['Volume'].astype(float)

        connection = sqlite3.connect(pyswing.database.pySwingDatabase)

        query = "insert or replace into Equities (Date, Open, High, Low, Volume, Close, Code) values (?,?,?,?,?,?,?)"
        connection.executemany(query, self._data.to_records(index=True))
        connection.commit()

        connection.close()

    def dataFrame(self):

        connection = sqlite3.connect(pyswing.database.pySwingDatabase)
        query = "select * from Equities where Code = '%s'" % (self._tickerCode)
        equityData = read_sql_query(query, connection, 'Date')
        connection.close()

        return equityData


    def _getLatestDate(self):

        connection = sqlite3.connect(pyswing.database.pySwingDatabase)

        query = "select max(Date) from Equities where Code = '%s'" % (self._tickerCode)

        cursor = connection.cursor()

        cursor.execute(query)
        dateString = cursor.fetchone()[0]

        connection.close()

        date = pyswing.constants.pySwingStartDate
        if dateString:
            date = datetime.datetime.strptime(dateString, "%Y-%m-%d %H:%M:%S")

        return date

    def _getTodaysDate(self):

        return datetime.datetime.now()
开发者ID:garyjoy,项目名称:pyswing,代码行数:86,代码来源:equity.py

示例8: dict

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import rename [as 别名]
# <codecell>

series = dict(jobs = "PAYEMS",
              income = "PI",
              prod = "INDPRO",
              cons = "PCEC96",
              prices = "CPIAUCSL")

# <codecell>

indicators = []
for variable in series:
    data = DataReader(series[variable], "fred", start="2010-1-1")
    # renaming not necessary in master
    data.rename(columns={"VALUE" : variable}, inplace=True)
    indicators.append(data)

# <codecell>

indicators = pandas.concat(indicators, axis=1)

# <codecell>

indicators

# <headingcell level=3>

# Polling Data

# <markdowncell>
开发者ID:TomAugspurger,项目名称:538model,代码行数:32,代码来源:silver_model.py


注:本文中的pandas.io.data.DataReader.rename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。