I am trying to remove all values in this pandas dataframe that have that have less than length 3, but not to all columns
import pandas
df = pd.DataFrame({'id': [1, 2, 3],'player': ['w', 'George', 'Roland'], 'hometown': ['Miami', 'Caracas', 'Mexico City'], 'current_city': ['New York', '-', 'New York']})
columns_to_add = ['player', 'hometown', 'current_city']
for column_name in columns_to_add:
df.loc[(len(df[column_name]) < 3), column_name] = None
I am trying the following code but I get the following error:
KeyError("cannot use a single bool to index into setitem")
Note: