0

I'm looking to select all columns that contain a string value in any of the rows and add that column to a list for manipulation later on.

Could you please help find the way? extract from my df:

d = {'1':['Q4 2018', 100, 111, 222], 
     '2':[2018, 333, 444, 555],
     '3':['Q1 2019', 55, 789, 70]}
df = pd.DataFrame(d)

I'd like to see a list of columns that contain value of 'Q1', 'Q2', 'Q3', 'Q4' anywhere in the column. In this case columns 1 and 3.

1 Answer 1

1

Using applymap with any

df.applymap(lambda x : 'Q' in str(x)).any()
Out[268]: 
1     True
2    False
3     True
dtype: bool
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.