API pull 的 Python 代码中的 AttributeError

AttributeError in Python code for API pull

对于不是我编写的代码,我收到以下错误。不确定此错误指示什么。我试过添加 'Series' 包,但它一直失败,但我什至不确定这是否是这里的问题。

错误信息:

Traceback (most recent call last):
  File "C:/Users/.../PycharmProjects/SocialActivityData/20181030_CE_SocialActivity_API_Call_manual (1).py", line 146, in <module>
    For_df_accountType.append(r.get_values().tolist()[0]['accountType'])

  File "C:\Users\...\AppData\Local\Temp181030_CE_SocialActivity_API_Call_manual (1).py\venv\lib\site-packages\pandas\core\generic.py", line 5274, in __getattr__
    return object.__getattribute__(self, name)

AttributeError: 'Series' object has no attribute 'get_values'

它引用的代码:

 ### looping through the nested attritutes column to flatten/normalize the column into a somple table with just the required columns

for i, r in df_DimensionsColumns.iterrows():
For_df_index.append(i)
For_df_accountType.append(r.get_values().tolist()[0]['accountType'])

try:
    For_df_message.append(r.get_values().tolist()[0]['content']['message'])
except:
    For_df_message.append('no message available from Sprinklr')
    pass

try:
    For_df_permalink.append(r.get_values().tolist()[0]['permalink'])
except:
    For_df_permalink.append('no permalink available from Sprinklr')
    pass

您不需要 'add the series package' 因为它应该包含在我假设您正在使用的内容中 -- Pandas

如果您查看 Series 上的文档,您会发现没有名为 get_values 的方法,这就是您在此处调用的方法:

For_df_accountType.append(r.get_values().tolist()[0]['accountType'])
                          # ^^ Right here

可能是您发现的脚本或程序利用了 Pandas 的早期版本,这导致了问题,因为您现在使用的是较新的版本。

这是关于 Series 的文档:https://pandas.pydata.org/pandas-docs/stable/reference/series.html

您可以尝试将 r.get_values().tolist()[0]['accountType'] 更改为 r.array[0]['accountType'] 的效果,或者 r.to_list()[0]['accountType'](根据 here),但我不能保证这会起作用因为我没有使用 Pandas.

的经验

文档是您最好的朋友,真的。