簡體   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