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


Python DataFrameClient.query方法代码示例

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


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

示例1: test_query_into_dataframe

# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import query [as 别名]
 def test_query_into_dataframe(self):
     data = [
         {
             "name": "foo",
             "columns": ["time", "sequence_number", "column_one"],
             "points": [
                 [3600, 16, 2], [3600, 15, 1],
                 [0, 14, 2], [0, 13, 1]
             ]
         }
     ]
     # dataframe sorted ascending by time first, then sequence_number
     dataframe = pd.DataFrame(data=[[13, 1], [14, 2], [15, 1], [16, 2]],
                              index=pd.to_datetime([0, 0,
                                                   3600, 3600],
                                                   unit='s', utc=True),
                              columns=['sequence_number', 'column_one'])
     with _mocked_session('get', 200, data):
         cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
         result = cli.query('select column_one from foo;')
         assert_frame_equal(dataframe, result)
开发者ID:MatijaB,项目名称:influxdb-python,代码行数:23,代码来源:dataframe_client_test.py

示例2: test_query_multiple_time_series

# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import query [as 别名]
 def test_query_multiple_time_series(self):
     """Test query for multiple time series."""
     data = [
         {
             "name": "series1",
             "columns": ["time", "mean", "min", "max", "stddev"],
             "points": [[0, 323048, 323048, 323048, 0]]
         },
         {
             "name": "series2",
             "columns": ["time", "mean", "min", "max", "stddev"],
             "points": [[0, -2.8233, -2.8503, -2.7832, 0.0173]]
         },
         {
             "name": "series3",
             "columns": ["time", "mean", "min", "max", "stddev"],
             "points": [[0, -0.01220, -0.01220, -0.01220, 0]]
         }
     ]
     dataframes = {
         'series1': pd.DataFrame(data=[[323048, 323048, 323048, 0]],
                                 index=pd.to_datetime([0], unit='s',
                                                      utc=True),
                                 columns=['mean', 'min', 'max', 'stddev']),
         'series2': pd.DataFrame(data=[[-2.8233, -2.8503, -2.7832, 0.0173]],
                                 index=pd.to_datetime([0], unit='s',
                                                      utc=True),
                                 columns=['mean', 'min', 'max', 'stddev']),
         'series3': pd.DataFrame(data=[[-0.01220, -0.01220, -0.01220, 0]],
                                 index=pd.to_datetime([0], unit='s',
                                                      utc=True),
                                 columns=['mean', 'min', 'max', 'stddev'])
     }
     with _mocked_session('get', 200, data):
         cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
         result = cli.query("""select mean(value), min(value), max(value),
             stddev(value) from series1, series2, series3""")
         self.assertEqual(dataframes.keys(), result.keys())
         for key in dataframes.keys():
             assert_frame_equal(dataframes[key], result[key])
开发者ID:bbc,项目名称:influxdb-python,代码行数:42,代码来源:dataframe_client_test.py

示例3: InfluxDB

# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import query [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
#.........这里部分代码省略.........
开发者ID:haomen,项目名称:PlayData,代码行数:103,代码来源:InfluxQuery.py

示例4: test_query_with_empty_result

# 需要导入模块: from influxdb.influxdb08 import DataFrameClient [as 别名]
# 或者: from influxdb.influxdb08.DataFrameClient import query [as 别名]
 def test_query_with_empty_result(self):
     with _mocked_session('get', 200, []):
         cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
         result = cli.query('select column_one from foo;')
         self.assertEqual(result, [])
开发者ID:MatijaB,项目名称:influxdb-python,代码行数:7,代码来源:dataframe_client_test.py


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