Home > Back-end >  AttributeError: 'Series' object has no attribute 'Mean_μg_L'
AttributeError: 'Series' object has no attribute 'Mean_μg_L'

Time:12-06

enter image description here

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 :

  1. Use replace right before the loop to get rid of this special character

    df.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, ..

  1. Use row["col_name"] (highly recommended) to refer to the column rather than row.col_name

     for 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()
    
  • Related