简体   繁体   中英

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

I have been working on a script on Python with pandas but I have no previous experience using the library.

I have been following a tutorial to complete this but this part of my code doesn't seem to be working(maybe outdated syntax) despite the instructions.

The error that I get is 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"]

It seems that webproperty which you are passing to the get_search_console_data() function, is None that makes the function return NoneType (actually nothing).
Check whether webproperty is None or not.
Otherwise the df which is being made in the function is None .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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