Here's what my dataframe looks like

Server  Performance123      Performance456                            
server1       1024             0
server2       110              0
server3       0                1024

Here's what I want it to ultimately look like

Server        Tier1
server1       1024
server2       110
server3       1024

Now obviously I could just add the two columns together but I can't be sure what the "123" or "456" part of the CSV I'm importing will look like as it's the last part of the UID of the datastore.

I've tried this

df['Tier 1'] = df.filter(like='Performance')

But I can't assign that as a new column in the dataframe. Any advice? I'm a bit of a newcomer to this so ran out of ideas quickly.


1 Answer 1


Well after much searching and a lot of errors I have the below working code

df['Tier 1'] = df.groupby(df.columns.str.contains('Performance'),axis=1).sum()[1]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.