简体   繁体   中英

How to Select Rows of Pandas Dataframe with one Column Value which has multiple values?

df = pd.DataFrame({'Fruits':['apple,guava','banana','orange'],'counts':[10,20,30]}) df.loc[df['Fruits']=='apple']

how can I get the count value as 10 with only one value ie apple?

It seems to me that you cannot get the count value with only one value "apple" as there is no such value present in your fruits column (you have guava and apple combined). You could split these two fruits into two separate column values, and get the count by:

df.iloc[row]['Fruits']

Where the row is where 'apple' is located.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM