0

I was trying to get new column using other timeseries index, however it has resulted in error. Here is

Code:

tesla_df = yf.download('TSLA',
                          interval = "1h",
                          start='2022-04-15', 
                          end='2022-05-30', 
                          progress=False,
    )
    tesla_df.index = tesla_df.index.tz_localize(None)
    tesla_df.index = pd.to_datetime(tesla_df.index)
    tesla_df['Weekday'] = tesla_df.index.weekday()
    tesla_df.head()

Error:

      7 tesla_df.index = tesla_df.index.tz_localize(None)
      8 tesla_df.index = pd.to_datetime(tesla_df.index)
----> 9 tesla_df['Weekday'] = tesla_df.index.weekday()
     10 tesla_df.head()
     11 #fig = px.line(tesla_df, x=tesla_df.index, y=tesla_df['Close'])

TypeError: 'Int64Index' object is not callable
  • Welcome to Stack Overflow. In your own words, where the code says `tesla_df.index.weekday()`, what do you expect that to mean? Specifically, what do you expect `tesla_df.index.weekday` to mean, and why should it make sense to put `()` after that? Did you try reading the documentation? – Karl Knechtel May 31 '22 at 00:36

1 Answers1

1

its a property and not a method. Try this, i.e., weekday without parenthesis

tesla_df['Weekday'] = tesla_df.index.weekday
Naveed
  • 11,495
  • 2
  • 14
  • 21