How to Make a Different List a Condition for a Value to Extract from a List

Asked 2 years ago, Updated 2 years ago, 111 views

 A = [1,1,1,...-1,1,1]
B = apple, banana
    0     333,      356
    1     364,      675
    2     643,      346
  .     ...,      ...
   344    325,      356

B reads csv as dataframe.
A and B are the same 345.
At this time, if A is 1, I would like to extract only the Apple value of B.
B.iloc [np.where(A>0)] extracts both apple and banana, so
B.iloc [np.where(A>0), 0], but I got an error when there were many indexes.

Is there a way to avoid taking it out with for as much as possible?

python3 pandas csv

2022-09-30 20:14

1 Answers

B.loc [A>0, 'apple']

Maybe it's OK to


2022-09-30 20:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.