Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中为批处理创建批?_Python_Pandas_Cassandra_Batch Processing - Fatal编程技术网

如何在python中为批处理创建批?

如何在python中为批处理创建批?,python,pandas,cassandra,batch-processing,Python,Pandas,Cassandra,Batch Processing,我有一个存储在cassandra中的数据,我想用python检索该数据以进行批处理。 我想基于时间列创建批处理。假设我在9:00:00和10:00:00之间从cassandra提取数据。现在我想为每分钟数据创建批处理。(同一时间戳可以在多行中) 这些批次将被馈送到其他模块,以便一个接一个地进行处理 我的代码如下: import pandas as pd from cassandra.cluster import Cluster cluster_cont=['127.0.0.1'] keysp

我有一个存储在cassandra中的数据,我想用python检索该数据以进行批处理。 我想基于时间列创建批处理。假设我在9:00:0010:00:00之间从cassandra提取数据。现在我想为每分钟数据创建批处理。(同一时间戳可以在多行中)

这些批次将被馈送到其他模块,以便一个接一个地进行处理

我的代码如下:

import pandas as pd
from cassandra.cluster import Cluster 

cluster_cont=['127.0.0.1']
keyspace='demo'
query='Select * from demo.table1'
cond1='9:00:00'
cond2='10:00:00'

def readD(cluster_cont, keyspace, query, cond1, cond2):

    cluster = Cluster(contact_points=cluster_cont)
    session = cluster.connect(keyspace)

    session.default_fetch_size = None

    rslt = pd.DataFrame(session.execute(query+" where time>="+cond1" and time<="+cond2, timeout=None))
    df = rslt._current_rows

return df
即使我能够在一段时间内进行迭代,我如何将这些数据帧一个接一个地提供给其他模块?我应该改变我的方法吗

欢迎提出任何建议。 谢谢


注:我正在使用python cassandra驱动程序提取数据。

cassandra中的数据检索模式严重依赖于表结构。请使用表的定义更新您的帖子
import pandas as pd
from cassandra.cluster import Cluster 

cluster_cont=['127.0.0.1']
keyspace='demo'
query='Select * from demo.table1'
cond1='9:00:00'
cond2='10:00:00'

def readD(cluster_cont, keyspace, query, cond1, cond2):

    cluster = Cluster(contact_points=cluster_cont)
    session = cluster.connect(keyspace)

    session.default_fetch_size = None

    rslt = pd.DataFrame(session.execute(query+" where time>="+cond1" and time<="+cond2, timeout=None))
    df = rslt._current_rows

return df
df=readD(cluster_cont, keyspace, query, cond1, cond2)
cond1=datetime.datetime.strptime(cond1,'%H:%M:%S').time()
cond2=datetime.datetime.strptime(cond2,'%H:%M:%S').time()

while cond1 <= cond2 :
   cond1 = cond1 + datetime.timedelta(minutes=1)
   df=df[df['time']==cond1]
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta'