pandas and calling function on an object

dataframe, pandas, python

Solution

class foo(object):
    @property
    def value(self):
        return "bar"


if __name__ == "__main__":
    a = [foo(), foo(), foo()]
    df = pd.DataFrame(data=a, columns=['test'])
    df['value'] = df['test'].apply(lambda x: x.value)
df

Problem

I have a column of type Object, and I want to access a property of the object into another column. ``` import pandas as pd class foo(object): @property def value(self): return "bar" if __name__ == "__main__": a = [foo(), foo(), foo()] df = pd.DataFrame(data=a, columns=['test']) df['value'] = df['test'].value ``` This fails with the following error: `AttributeError: 'Series' object has no attribute 'value'` Is there a way to call a property or function on a class to populate a new column?

Original source