yasin mohammed yasin mohammed - 1 year ago 74
Python Question

Move Values of a dataframe to a list based on a condition

I am trying to move the data from a single column in a dataframe to a list.

Account Name Renewal % Change
Client 1 0%
Client 2 0%
Client 3 2%
Client 4 0%
Client 5 1%
Client 6 1%

So If a client has 0% It should get added to the list Cost0 and it it has 1% it should get added to Cost1.

I tried using a pd.series.tolist() but it kept giving me an error.

if brl['Renewal % Change'] == '0%':
a = pd.Series(brl['Account Name'])

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

Please advise

Answer Source

Try this

Cost0 = brl[blr['Renewal % Change']=='0%']['Account Name'].tolist()
Cost1 = brl[blr['Renewal % Change']=='1%']['Account Name'].tolist()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download