繁体   English   中英

我得到的错误是 AttributeError: 'NoneType' object has no attribute 'date'

[英]The error that I get is AttributeError: 'NoneType' object has no attribute 'date'

我一直在使用 Python 和 pandas 编写脚本,但我以前没有使用该库的经验。

我一直在按照教程完成此操作,但尽管有说明,我的这部分代码似乎无法正常工作(可能是过时的语法)。

我得到的错误是 AttributeError: 'NoneType' object has no attribute 'date':

def get_search_console_data(webproperty, days=-365):
  if webproperty is not None:
    query = webproperty.query.range(start='today', days=days).dimension('date', 'query')
    r = query.get()
    df = pd.DataFrame(r.rows)
    return df

  print("Web property doesn't exist, please select a valid one from this list")
  print(account.webproperties)

df = get_search_console_data(webproperty)
     

    df["date"] = pd.to_datetime(df.date)

    df[df["date"] > "2021-10-3"]

last_day_queries = df[df["date"] > "2021-10-3"]["query"]
rest_of_queries = df[df["date"] < "2021-10-3"]["query"]

您传递给get_search_console_data() function 的webproperty似乎是None ,这使得 function 返回NoneType (实际上什么都没有)。
检查webproperty是否为None
否则在 function 中制作的dfNone

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM