Filter and append columns into one in Pandas

2756 views python
1

sht.head()

enter image description here

How Can I create a column K containing all non-zero-values from A:J?

K = ["A001", "B001", "C001", "D001", "E001", "A002", ...]

answered question

1 Answer

6

Use agg in axis=1

df['K'] = df.agg(lambda s: tuple(s[s!=0]), axis=1)

posted this

Have an answer?

JD

Please login first before posting an answer.