相关疑难解决方法(0)

Python将Cassandra数据读入熊猫

什么是正确的和最快的方式来读取数据卡珊德拉到熊猫吗?现在我使用以下代码,但它很慢......

import pandas as pd

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import dict_factory

auth_provider = PlainTextAuthProvider(username=CASSANDRA_USER, password=CASSANDRA_PASS)
cluster = Cluster(contact_points=[CASSANDRA_HOST], port=CASSANDRA_PORT,
    auth_provider=auth_provider)

session = cluster.connect(CASSANDRA_DB)
session.row_factory = dict_factory

sql_query = "SELECT * FROM {}.{};".format(CASSANDRA_DB, CASSANDRA_TABLE)

df = pd.DataFrame()

for row in session.execute(sql_query):
    df = df.append(pd.DataFrame(row, index=[0]))

df = df.reset_index(drop=True).fillna(pd.np.nan)
Run Code Online (Sandbox Code Playgroud)

读取1000行需要1分钟,我有一点"更多"...如果我运行相同的查询,例如.在DBeaver中,我在一分钟内得到了整个结果(~40k行).

谢谢!!!

python cassandra pandas

17
推荐指数
2
解决办法
7705
查看次数

标签 统计

cassandra ×1

pandas ×1

python ×1