我正在使用Cassandra Python driver
,我创建了一个表,在表中有一个列(称为日期)定义为timestamp
。我尝试从数据框访问值,并使用这些值将行插入表中。与date对应的数据帧值具有格式(从PyCharm
调试模式捕获),
Timestamp('2006-09-29 00:00:00')
但是我收到了以下错误,
TypeError: Received an argument of invalid type for column "date". Expected: <class 'cassandra.cqltypes.DateType'>, Got: <class 'str'>; (DateType arguments must be a datetime, date, or timestamp)
该表定义为,
CREATE TABLE test_keyspace.test_table (
key1 text PRIMARY KEY,
key2 float,
key3 text,
key4 text,
key5 text,
date timestamp
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
更新
问题是由于数据框中有NaT而在将它们插入cassandra之前忘记删除它们。
答案 0 :(得分:1)
尝试使用datetime.datetime(2016,09,29)
代替