Run "Procv" on a Dataframe Pandas

Asked

Viewed 1,875 times

1

I have a Dataframe in pandas containing a listing with values similar to these:

     a  e    r
0   88  6 -496
1    8  2 -188
2   76  5 -482
3   78  4   24
4   19  1 -346
5   40  1 -346
6   61  0 -224
7   79  1 -346
8   64  4   24
9   86  0 -224
10  47  1 -346
11  49  0 -224

I would like to perform a procedure similar to Excel "procv" for column values e in relation to column r (filter single column values and check corresponding values for column r): Ex:

0 -224
1 -346
2 -188
4   24
5 -482
6 -496

find the unique values of e I could see:

df['e'].unique()

but I’m unable to filter the values of r and generate a dataframe with the results.

Thank you very much!

1 answer

1


For data.frames the method for taking repeated data from a column is drop.duplicates(). And sort_values() to leave the values in the ascending order of a column.

nova_df = df[['e','r']].drop_duplicates('e').sort_values('e')

With this the result already comes in another data frame.

  • It worked perfectly, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.