0

In this answer, we can see that pd.cut() results in a column of type category and that .apply() allows access to the properties of a given interval value.

For example, this works:

df['b'] = df['a'].apply(lambda x: x.left)

But this does not work:

df['b'] = df['a'].left

I don't understand why this is. Couldn't find a good explanation. If someone can explain, that would be great.

dgLurn
  • 51
  • 7

1 Answers1

0

AmineBTG's comment on the question answers it.

In the following, .left applies to the series and there is no left method (or property) for pd.series

df['b'] = df['a'].left

In the following, .apply() works row-wise and acts on the series values one at a time. So .left is correctly interpreted as a property of each [interval] value.

df['b'] = df['a'].apply(lambda x: x.left)
dgLurn
  • 51
  • 7