Python ';非类型';列中的对象
我使用数组并将行命名为列[1]中的元素Python ';非类型';列中的对象,python,pandas,Python,Pandas,我使用数组并将行命名为列[1]中的元素 free.index = free[1] free 下一步,我想删除列[1] free = free.drop(1, axis=1, inplace=True) free 结果是 AttributeError Traceback (most recent call last) <ipython-input-24-1a43fda6165c> in <module> ----&g
free.index = free[1]
free
下一步,我想删除列[1]
free = free.drop(1, axis=1, inplace=True)
free
结果是
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'
如何避免错误 您得到的是AttributeError:'NoneType'对象没有属性'drop',因为NoneType意味着您实际上没有得到任何类或对象的实例,而不是您认为正在使用的类或对象的实例。这意味着上述赋值或函数调用失败或返回意外结果
free = free.drop (['free'], 1, inplace=True)
也检查这些
您得到的是AttributeError:“NoneType”对象没有属性“drop”,因为NoneType意味着您实际上没有得到您认为正在使用的任何类或对象的实例。这意味着上述赋值或函数调用失败或返回意外结果
free = free.drop (['free'], 1, inplace=True)
也检查这些
以下是一些示例。请注意,列由标签引用
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)```
这里有一些例子。请注意,列由标签引用
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)```