May-17-2022, 08:50 AM
import mysql.connector import pandas as pd def to_camel_case(col_name: str) -> str: #""function to convert column names to camel case""" if '_' in col_name: components = col_name.split('_') elif ' ' in col_name: components = col_name.split(' ') else: return col_name # We capitalize the first letter of each component except the first one # with the 'title' method and join them together. return components[0] + ''.join(x.title() for x in components[1:]) my_conn = mysql.connector.connect( host="localhost", user="admin", passwd="******", database="dbname" ) cursor = my_conn.cursor(buffered=True) ####### end of connection #### #my_data = pd.read_sql("SELECT * FROM admin_user",my_conn) #print(my_data) tables_mysql = pd.read_sql_query("SHOW TABLES", my_conn) print(tables_mysql) for table in tables_mysql["Tables_in_{}".format('dbname')]: print(table) query = f"SELECT * FROM {table}" table_chunks = pd.read_sql_query(query, my_conn, chunksize=100000) for chunk in table_chunks: table_cols = chunk.columns print(table_cols) new_col_names = [] for col_name in table_cols: new_col_names.append(to_camel_case(col_name)) chunk.columns = new_col_names print(chunk.columns) print('====')When i run this code i got this error. What is the solution?
f"Length mismatch: Expected axis has {old_len} elements, new " ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements