Home > Blockchain >  Key error for Level Values Raise Key Error(key)
Key error for Level Values Raise Key Error(key)

Time:08-27

Anyone know why I am getting a Level_Values raise KeyError, my guess is there are too many of the same date value? or something. I can see the values when I do a .get('new date') it just won't sort the column:

df = pd.read_csv("Status 9 Data.csv", header=0, sep=",")

##df.columns = ["JOB_REFERENCE","STATUS","DESCRIPTION","JOB_STATUS","EVENT_DATE","SERVICE_NO","SERVICE_NUM","BKG_PTY_NAME","REFRIGERATED","OVERSIZE_FLAG","TEU_UTILISATION","FIELD_CHARACTER_NEW","FIELD_CHARACTER_OLD","FIELD_CHANGE_CODE"]

df['new date'] = pd.to_datetime(df['EVENT_DATE']).dt.normalize()

df.sort_values(by=df['new date'], inplace=True, ascending=False)

df

CodePudding user response:

The Error you should pass in by the name of the column new date not the data like df["new date"]

df.sort_values(by='new date', inplace=True, ascending=False)
  • Related