I want to create a new class that allows me to create pandas Series objects that are restricted so the user only needs to enter a start date and number of periods to initialize the series. I also want to be able to replace values given a date within that series. I made an attempt below but I'm getting
AttributeError: can't set attribute
When I try to assign the Series.values as shown below. How can I create my class by inheriting from Series like this?
import pandas as pd
import numpy as np
class TimeSeries(Series):
def __init__(self, start_date='1/1/2019', periods=365):
Series.__init__(self)
self.range = pd.date_range(start_date, periods=periods, freq='D')
self.values = pd.Series(np.zeros(len(self.range)), index=self.range)
def set_value(self, at_date, value):
self.values[at_date] = value