Why am I getting this error if the column name exists.
I have tried everything. I am out of ideas
CodePudding user response:
Since the AttributeError is raised at the first column with a name containing a mathematical symbol (µ), I would suggest you these two solutions :
Use
replaceright before the loop to get rid of this special characterdf.columns = df.columns.str.replace("_\wg_", "_ug_", regex=True) #change df to Table_1_1a_Tarawa_Terrace_System_1975_to_1985
Then inside the loop, use row.Mean_ug_L, .. instead of row.Mean_µg_L, ..
Use
row["col_name"](highly recommended) to refer to the column rather thanrow.col_namefor index, row in Table_1_1a_Tarawa_Terrace_System_1975_to_1985.iterrows(): SQL_VALUES_Tarawa = (row["Chemicals"], rows["Contamminant"], row["Mean_µg_L"], row["Median_µg_L"], row["Range_µg_L"], row["Num_Months_Greater_MCL"], row["Num_Months_Greater_100_µg_L"]) cursor.execute(SQL_insert_Tarawa, SQL_VALUES_Tarawa) counting = cursor.rowcount print(counting, "Record added") conn.commit()

