I am at the beginning of learning pandas, I have data frame about cars and I want to return the models of car that are automatic and manufactured in the last two years. I am trying to write the code as below:
df.loc[((df[['year']].drop_duplicates().nlargest(2, 'year')) && (df.loc[df['Sparetype'] =='Automatic'])) ,'model']
But I get this error:
File "C:\Users\Hala\AppData\Local\Temp/ipykernel_3412/2229436407.py", line 1
df.loc[((df[['year']].drop_duplicates().nlargest(2, 'year')) && (df.loc[df['Sparetype'] =='Automatic'])) ,'model']
^
SyntaxError: invalid syntax
When I replace &&
to &
I get this error:
TypeError: unsupported operand type(s) for &: 'float' and 'int'