To create a pandas.Series
from a generic object, the following can be used:
import datetime
class Test(object):
def __init__(self):
self.creation = datetime.datetime.now()
a = Test()
c = pandas.Series(a.__dict__)
This results in a Series that is described as
creation 2017-12-17 09:51:48.157503
dtype: datetime64[ns]
This failed to work if the object contains "attributes" created using @property
, like so
class Test(object):
def __init__(self):
self.creation = datetime.datetime.now()
@property
def as_string(self):
return 'Test at {}'.format(self.creation)
a = Test()
c = pandas.Series(a.__dict__) # same as above
How can the object's properties be included in the Series
? Or is there an easier way to create a Series
from a generic object, including its properties?