python学习|python错误AttributeError: 'DataFrame' object has no attribute 'tolist'

最近在对dataframe进行操作时出现错误:
执行代码如下:

direction = set(df_i[['lane_id']].tolist()) #获取路口方向字典

此时报错码:
Traceback (most recent call last): File "test1.py", line 12, in direction = set(df_i[['lane_id']].tolist()) #获取路口方向字典 File "F:\anaconda\lib\site-packages\pandas\core\generic.py", line 5067, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'tolist'

问题很简单,选取dataframe列时,双括号返回的是dataframe格式,没有tolist功能
改为单括号,返回series格式
修改后:
direction = set(df_i['lane_id'].tolist()) #获取路口方向字典

【python学习|python错误AttributeError: 'DataFrame' object has no attribute 'tolist'】问题解决:
python学习|python错误AttributeError: 'DataFrame' object has no attribute 'tolist'
文章图片

    推荐阅读