ande.ANDE.resample("M").last()


TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_108972\3489082683.py in
----> 1 ande.ANDE.resample(“M”).last()

~\anaconda3\lib\site-packages\pandas\core\series.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
5426 offset: TimedeltaConvertibleTypes | None = None,
5427 ) → Resampler:
→ 5428 return super().resample(
5429 rule=rule,
5430 axis=axis,

~\anaconda3\lib\site-packages\pandas\core\generic.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
8311
8312 axis = self._get_axis_number(axis)
→ 8313 return get_resampler(
8314 self,
8315 freq=rule,

~\anaconda3\lib\site-packages\pandas\core\resample.py in get_resampler(obj, kind, **kwds)
1421 “”"
1422 tg = TimeGrouper(**kwds)
→ 1423 return tg._get_resampler(obj, kind=kind)
1424
1425

~\anaconda3\lib\site-packages\pandas\core\resample.py in _get_resampler(self, obj, kind)
1597 return TimedeltaIndexResampler(obj, groupby=self, axis=self.axis)
1598
→ 1599 raise TypeError(
1600 "Only valid with DatetimeIndex, "
1601 "TimedeltaIndex or PeriodIndex, "

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’

When I use ande.ANDE.resample(“M”).last(), it doesn’t work. May I know how to fix this?

You would need to post your full code.

To add code into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

`ANDE.ANDE.resample(“M”).last()````

TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_117200\2629291969.py in
----> 1 ANDE.ANDE.resample(“M”).last()

~\anaconda3\lib\site-packages\pandas\core\series.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
5426 offset: TimedeltaConvertibleTypes | None = None,
5427 ) → Resampler:
→ 5428 return super().resample(
5429 rule=rule,
5430 axis=axis,

~\anaconda3\lib\site-packages\pandas\core\generic.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
8311
8312 axis = self._get_axis_number(axis)
→ 8313 return get_resampler(
8314 self,
8315 freq=rule,

~\anaconda3\lib\site-packages\pandas\core\resample.py in get_resampler(obj, kind, **kwds)
1421 “”"
1422 tg = TimeGrouper(**kwds)
→ 1423 return tg._get_resampler(obj, kind=kind)
1424
1425

~\anaconda3\lib\site-packages\pandas\core\resample.py in _get_resampler(self, obj, kind)
1597 return TimedeltaIndexResampler(obj, groupby=self, axis=self.axis)
1598
→ 1599 raise TypeError(
1600 "Only valid with DatetimeIndex, "
1601 "TimedeltaIndex or PeriodIndex, "

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’

ANDE

ANDE

Date
2010-01-04 00:00:00-05:00 17.586666
2010-01-05 00:00:00-05:00 17.520000
2010-01-06 00:00:00-05:00 17.453333
2010-01-07 00:00:00-05:00 17.326668
2010-01-08 00:00:00-05:00 16.973333
… …
2022-12-23 00:00:00-05:00 36.020000
2022-12-27 00:00:00-05:00 36.639999
2022-12-28 00:00:00-05:00 35.070000
2022-12-29 00:00:00-05:00 35.439999
2022-12-30 00:00:00-05:00 34.990002
3272 rows × 1 columns

ANDE.ANDE.resample(“M”).last()


TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_117200\2629291969.py in
----> 1 ANDE.ANDE.resample(“M”).last()

~\anaconda3\lib\site-packages\pandas\core\series.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
5426 offset: TimedeltaConvertibleTypes | None = None,
5427 ) → Resampler:
→ 5428 return super().resample(
5429 rule=rule,
5430 axis=axis,

~\anaconda3\lib\site-packages\pandas\core\generic.py in resample(self, rule, axis, closed, label, convention, kind, loffset, base, on, level, origin, offset)
8311
8312 axis = self._get_axis_number(axis)
→ 8313 return get_resampler(
8314 self,
8315 freq=rule,

~\anaconda3\lib\site-packages\pandas\core\resample.py in get_resampler(obj, kind, **kwds)
1421 “”"
1422 tg = TimeGrouper(**kwds)
→ 1423 return tg._get_resampler(obj, kind=kind)
1424
1425

~\anaconda3\lib\site-packages\pandas\core\resample.py in _get_resampler(self, obj, kind)
1597 return TimedeltaIndexResampler(obj, groupby=self, axis=self.axis)
1598
→ 1599 raise TypeError(
1600 "Only valid with DatetimeIndex, "
1601 "TimedeltaIndex or PeriodIndex, "

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’


Here is the full code. Do you think you know why it has this error?

Can you post the code without the line numbers? I can not tell what is code and what is output.

Can you put your code in a replit or something with only the code, so that we can attempt to run the code?

import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

ticker = [“ZIM”,“ANDE”,“ARKK” ]

stocks = yf.download(ticker, start = “2010-01-01”, end = “2023-01-01”)

ANDE

ANDE.ANDE.resample(“M”).last()


Here you are