Reputation: 521
import pandas as pd
df = pd.DataFrame({'Name': ['dd','ee','ff'], 'Toy-Figure': [2,3,1], 'Toy-car':[1,2,0], 'Toy-blocks':[5,9,0]})
For the above df, I want all Names who have more than 1 toy. Here's what I have so far, but I can't get the names column. How do I do that ?
df_c = df.copy()
df_c[df_c.sum(axis = 1) > 1].sum(axis=1)
Upvotes: 1
Views: 50
Reputation: 738
I'll simply add to your solution,
df_c = df.copy()
df_c.index = df_c['Name']
df_c[df_c.sum(axis = 1) > 1].sum(axis=1)
or
df.sum(axis = 1)[df.sum(axis = 1) >1]
Upvotes: 1