Insert Pandas Dataframe Into Cassandra Table
From the documentation , there is a way to insert data into table: session.execute( ''' INSERT INTO users (name, credits, user_id) VALUES (%s, %s, %s) ''', ('Jo
Solution 1:
You can get the Dataframe's column names with the following
column_names = list(my_dataframe.columns.values)
You could rewrite insert_table(...)
to accept the list of column names as an argument.
For example, string substitution can be used to form the CQL statement:
cql_query = """
INSERT INTO {table_name} ({col_names})
VALUES (%s, %s, %s)
""".format(table_name="my_table", col_names=','.join(map(str, column_names)))
...
Post a Comment for "Insert Pandas Dataframe Into Cassandra Table"