1

I have a dataframe where most of values are stored as list. That is unnecessary to me. I would like to convert those list into their first(and only member). That is to say, I would like to value = value[0]. But this does not work

All in all: How to "unlist" all values in dataframe?

1 Answer 1

2

Probably you can use .applymap. Something like:

>>> unlist = lambda l: l[0] if len(l) != 0 else None
>>> unwrap = lambda l: unlist(l) if isinstance(l, list) else l
>>> df.applymap(unwrap)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.