This is the look of my DataFrame:
StateAb GivenNm Surname PartyNm PartyAb ElectedOrder 35 WA Joe BULLOCK Australian Labor Party ALP 2 36 WA Michaelia CASH Liberal LP 3 37 WA Linda REYNOLDS Liberal LP 4 38 WA Wayne DROPULICH Australian Sports Party SPRT 5 39 WA Scott LUDLAM The Greens (WA) GRN 6
and I want to list a list of senators whose surname is more than 9 characters long.
So I think the code should be like this:
df[len(df.Surname) > 9]
but this raises a KeyError, where did I go wrong?
df[df['Surname'].apply(len) > 9]by the way which evaluates each string present in the series and returnsTrueif the condition is satisfied. - Nickil Maveli