I updated Pandas to 1.4.0 with yfinance 0.1.70. Previously, I had to stay with Pandas 1.3.5 as Pandas and yfinance did't play well together. These latest versions of Pandas and yfinance now work together, BUT Pandas now gives me this warning:
Future Warning: Passing method to DatetimeIndex.get_loc is deprecated... Use index.get_indexer([item], method=...) instead
I had enough trouble as a novice Python person getting the original get_loc statement to work:
last_week = format((df.index[df.index.get_loc(last_week, method='nearest')]).strftime('%Y-%m-%d'))
This statement allowed me to get a date from the dataframe that I could use further in determining the value associated with that date:
week_value = df.loc[last_week, ans]
Truth be known, I am intimidated in trying to change this statement to be compliant with the new and improved get_indexer function. Can someone help me out please?
CodePudding user response:
Should be pretty simple. Just change get_loc(XXX, ...) to get_indexer([XXX], ...)[0]:
last_week = format((df.index[df.index.get_indexer([last_week], method='nearest')[0]]).strftime('%Y-%m-%d'))
