无法在 Apache Cassandra 中将值转换为浮点数

问题描述 投票:0回答:0

这是我遇到的错误,我已经在第一部分中提到了我用于创建表的代码。我知道 csvreader 以字符串格式获取数据,但类型转换不起作用。

create_table1 = """
        CREATE TABLE IF NOT EXISTS song_info_by_session (
        session_id int, 
        item_in_session int, 
        artist_name varchar,
        length float, 
        song text,  
        PRIMARY KEY(session_id, item_in_session))
"""

try:
    session.execute(create_table1)
except Exception as e:
    print(e)
file = 'event_datafile_new.csv'

with open(file, encoding = 'utf8') as f:
    csvreader = csv.reader(f)
    next(csvreader) # skip header
    for line in csvreader:
        insert_table1 = """INSERT INTO song_info_by_session  
                    (session_id, 
                    item_in_session,
                    artist_name, 
                    length, 
                    song) 
                """
        insert_table1 = insert_table1 + "VALUES (%s, %s, %s, %s, %s)"
        session.execute(insert_table1, (int(line[8]), int(line[3]), line[0], float(line[5]), line[9]))

python database apache cassandra nosql
© www.soinside.com 2019 - 2024. All rights reserved.