0

I worked with an array and named rows as elements in a column [1]

free.index = free[1]
free

Next step, I wanted to delete column[1]

free = free.drop(1, axis=1, inplace=True)
free

The result is

AttributeError                            Traceback (most recent call last)
<ipython-input-24-1a43fda6165c> in <module>
----> 1 free = free.drop(1, axis=1, inplace=True)
      2 free
AttributeError: 'NoneType' object has no attribute 'drop'

The same is then I write

free.columns

How an error could be avoid?

2 Answers2

1

You are getting AttributeError: 'NoneType' object has no attribute 'drop' because NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None. It means that an assignment or function call up above failed or returned an unexpected result.

free = free.drop (['free'], 1, inplace=True)

Check these also;

Understanding inplace True

Unable to drop column, object has no attribute drop

Yagiz Degirmenci
  • 16,595
  • 7
  • 65
  • 85
1

Here are some examples. Please note that column are referenced by label.

import pandas
free = pandas.DataFrame([], columns=['a', 'b', 'c', 'd'])
print(free)

# to delete the row named 'a'
free = free.drop(['a'], axis=1)
print(free)

# to delete the first row (here, it will be column 'b')
free = free.drop( free.columns[0], axis=1)
print(free)

# to delete the row 'd' with inplace=True (you don't need to tyhpe `free =` )
free.drop(['d'], axis=1, inplace=True)
print(free)```
pyOliv
  • 1,253
  • 1
  • 6
  • 21