1

I have a newly created Pandas dataframe, which for some reason I can't drop the columns from.

RangeIndex: 2617 entries, 0 to 2616 Columns: 111 entries, access to zoning dtypes: object(111) memory usage: 2.2+ MB None

print list(df)

['access', 'age', 'attic', 'basement_type', 'bathrooms', 'bedrooms_total', 'buyer', 'buyer_city', 'buyer_country', 'buyer_postal_code', 'colisting_agent_id', 'construction', 'csa_number', 'date_expired_hidden', 'date_listed', 'date_sold', 'date_unconditional', 'distance_to_schools', 'distance_to_transportation', 'district', 'ensuites', 'exterior_features', 'exterior_finish', 'fireplace_types', 'fireplaces', 'flooring', 'fuel', 'heating', 'id', 'interior_features', 'internet_remarks']

df = df.drop(['buyer', 'buyer_city', 'buyer_country', 'colisting_agent_id'], axis=1, inplace=True)


print list(df)```



TypeErrorTraceback (most recent call last)
<ipython-input-63-1db0e7488634> in <module>()
      6 
      7 
----> 8 print list(df)

TypeError: 'NoneType' object is not iterable
0

2 Answers 2

1

The inplace=True argument will drop at the source i.e. the dataframe itself and returns None.

So, when you use inplace=True then don't assign it back to df

Here the error is because the df variable is assigned to None and calling a list constructor on None will raise an error.

>>> df.drop(list_of_cols_to_drop, axis=1, inplace=True)
Sign up to request clarification or add additional context in comments.

1 Comment

makes total sense! Thank you
1

Either you should do:

df = df.drop(['buyer', 'buyer_city', 'buyer_country'], axis=1)

Or:

df.drop(['buyer', 'buyer_city', 'buyer_country'], axis=1, inplace=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.