Skip to content

apply with values return wrong output without convert to list #17487

Closed
@jesrael

Description

@jesrael

from SO

df = pd.DataFrame({'a':[1,2], 'b':[2,3]})
print (df)
   a  b
0  1  2
1  2  3

And output is wrong:

print (df.apply(lambda x: [x.values]))
a    [[8791439669712, 8791439669712]]
b    [[8791439669712, 8791439669712]]
dtype: object

But if convert to list all working nice:

print (df.apply(lambda x: [x.values.tolist()]))
a    [[1, 2]]
b    [[2, 3]]
dtype: object

print (df.apply(lambda x: [list(x.values)]))
a    [[1, 2]]
b    [[2, 3]]
dtype: object

What is problem?

Metadata

Metadata

Assignees

Labels

ApplyApply, Aggregate, Transform, MapBugNeeds TestsUnit test(s) needed to prevent regressionsNested DataData where the values are collections (lists, sets, dicts, objects, etc.).good first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions