我正在尝试使用 Python 将 Cassandra 表导出为 CSV 格式。但我做不到。但是,我可以从 Python 执行“select”语句。我使用了以下代码:
from cassandra.cluster import Cluster
cluster = Cluster ()
session = cluster.connect('chandan') ### 'chandan' is the name of the keyspace
## name of the table is 'emp'
session.execute(""" copy emp (id,name) to 'E:\HANA\emp.csv' with HEADER = true """ )
print "Exported to the CSV file"
Run Code Online (Sandbox Code Playgroud)
请在这方面帮助我。
我有一个清单
a=[('policy', 871),
('insurance', 382),
('life', 357),
('request', 270),
('call', 260)]
Run Code Online (Sandbox Code Playgroud)
现在,我想将其转换为一个项目的列表dict:
[{'call': 260},{'insurance': 382},{'life': 357}, {'policy': 871}, {'request': 270}]
Run Code Online (Sandbox Code Playgroud)