Search code examples
pandascsvattributeerror

why drop row got error AttributeError: 'DataFrame' object has no attribute 'No'


Hi I am trying to drop a row from a Data frame, loaded from a CSV file:

no_show_raw_data = pd.read_csv("noshowappointments.csv")

df = no_show_raw_data

new_df = df[df.No-show != 'No']

but i get this error:

AttributeError: 'DataFrame' object has no attribute 'No'


Solution

  • The columns No-show has a minus sign in the name, try brackets instead:

    no_show_raw_data = pd.read_csv("noshowappointments.csv")
    
    df = no_show_raw_data
    
    new_df = df[df['No-show'] != 'No']