本文整理汇总了Python中influxdb.influxdb08.DataFrameClient.switch_database方法的典型用法代码示例。如果您正苦于以下问题:Python DataFrameClient.switch_database方法的具体用法?Python DataFrameClient.switch_database怎么用?Python DataFrameClient.switch_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类influxdb.influxdb08.DataFrameClient
的用法示例。
在下文中一共展示了DataFrameClient.switch_database方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DataFrameClient
# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import switch_database [as 别名]
[ 'wage_us_yoy', '(wage_us_weekly_nonsupervisory/lag(wage_us_weekly_nonsupervisory,12)-1)*100' ],
[ 'wti_yoy', '(avg(wti_spot,M)/lag(avg(wti_spot,M),12)-1)*100' ],
[ 'zillow_median_sale_price_yoy', '(zillow_median_sale_price/lag(zillow_median_sale_price,12)-1)*100' ],
[ 'ng_yoy', '(ng_hh_spot/lag(ng_hh_spot,12)-1)*100' ],
[ 'gdp_us_yoy', '(gdp_us/lag(gdp_us,4)-1)*100' ],
]
processed_list = [
[ 'wage_lag_15m', 'mlag(wage_us_yoy,15)' ],
[ 'zillow_median_sale_price_15m', 'mlag(zillow_median_sale_price_yoy,15)' ],
]
df = DataFrameClient('localhost',8086,'root','root')
if({'name':'Econ'} not in df.get_list_database()):
df.create_database('Econ')
df.switch_database('Econ')
#add all items in interested list
start = timeit.default_timer()
for item in interest_list:
if item[0] in df.get_list_series():
df.delete_series(item[0])
results = influx_Fred.interpret(item[1])
results = results.replace(to_replace='NaN',value='.')
results = DataFrame({'value':results['value']})
df.write_points({item[0]:results})
print item
print 'total time in seconds: %.2f' % (timeit.default_timer() - start)
#add all items in processed list
start = timeit.default_timer()
示例2: QuandlAPI
# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import switch_database [as 别名]
'''
Created on Jul 8, 2015
@author: shaunz
'''
from QuandlAPI import QuandlAPI
from influxdb.influxdb08 import DataFrameClient
from QuandlTicker import Quandl_ticker_list
import timeit
quandl = QuandlAPI()
df = DataFrameClient('localhost', 8086, 'root', 'root')
if({'name':'Quandl'} not in df.get_list_database()):
df.create_database('Quandl')
df.switch_database('Quandl')
for series in df.get_list_series():
df.delete_series(series)
start = timeit.default_timer()
for item in Quandl_ticker_list:
results = quandl.get_series(item[1],item[2],item[3])
results = results.replace(to_replace='NaN',value='.')
print item
df.write_points({item[0]:results})
print 'total time in seconds: %.2f' % (timeit.default_timer() - start)
示例3: InfluxDB
# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import switch_database [as 别名]
class InfluxDB(object):
'''
Connect to influxdb and pull/write data
'''
def __init__(self, db_name=None):
self.url = 'localhost'
self.port = 8086
self.user = 'root'
self.password = 'root'
self.db_list = [ 'FRED', 'Quandl', 'Econ', 'ChinaData' ]
self.db = DataFrameClient(self.url, self.port, self.user, self.password)
if(db_name != None):
self.db_name = db_name
self.db.switch_database(db_name)
def _search_db(self,series_name):
'''
Search the db name for a series name
'''
for db in self.db_list:
temp_db = DataFrameClient(self.url, self.port, self.user, self.password, db)
if series_name in temp_db.get_list_series():
return db
return None
def query(self,series_name,db_name=None):
'''
Query a particular series
------
series_name: str
name of the series, e.g. "CPI_US"
------
return a pandas DataFrame with NaN representing missing values
------
'''
if(db_name != None):
self.db.switch_database(db_name)
results = self.db.query('SELECT * FROM %s' % series_name)
else:
db_name = self._search_db(series_name)
self.db.switch_database(db_name)
results = self.db.query('SELECT * FROM %s' % series_name)
if(results['value'].str.contains('.').isnull().sum()!=len(results)):
results.loc[results['value']=='.','value'] = None
return results.astype(float)
def _is_num(self, s):
'''
Determine if a string is a number
'''
try:
float(s)
return True
except ValueError:
return False
def _include(self,expression_list,c):
'''
check whether expression_list include basic operator c, and give the index of first occurrence
------
c: str
the basic operator or parentheses c
------
'''
for index, item in enumerate(expression_list):
if(type(item)==type('string')):
if(item == c):
return index
return -1
def _get_index(self,expression_list, op_1, op_2):
'''
Get the index of first occurrence of op_1 OR op_2, assume expression_list includes op_1 OR op_2
'''
index_1 = self._include(expression_list, op_1)
index_2 = self._include(expression_list, op_2)
if(min(index_1,index_2)==-1):
return(max(index_1,index_2))
else:
return(min(index_1,index_2))
def _close_parentheses(self,expression):
'''
Find the closing parentheses to the first opening (
------
expression: str
str contains an opening (
------
'''
layer = 0
for i, char in enumerate(expression):
if(char=='('):
layer = layer + 1
#.........这里部分代码省略.........
示例4: FredLink
# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import switch_database [as 别名]
'''
Created on Jul 2, 2015
@author: shaunz
'''
from influxdb.influxdb08 import DataFrameClient
from pandas import DataFrame
from FredAPI import FredLink
from FredLink.FredTicker import Fred_ticker_list
import timeit
fred = FredLink()
df = DataFrameClient('localhost', 8086, 'root', 'root')
if({'name':'FRED'} not in df.get_list_database()):
df.create_database('FRED')
df.switch_database('FRED')
for series in df.get_list_series():
df.delete_series(series)
start = timeit.default_timer()
for item in Fred_ticker_list:
results = fred.get_series(item[1])
results = results.replace(to_replace='NaN',value='.')
data = DataFrame({'value': results})
print item
df.write_points({item[0]:data})
print 'total time in seconds: %.2f' % (timeit.default_timer() - start)