How to find row value for multiple columns using Pandas

Viewed 55

I have the following dataset:

enter image description here

I want to find the average user rating and user rating count for the game PUBG MOBILE.

I tried the following line but it does not work at all:

df.loc[df['Name']['Average.User.Rating']['User.Rating.Count'] == 'PUBG MOBILE']

I also would find the names of the strategy games with the average user rating ≥ 4.5 and with the user rating count ≥ 300000 but I don't know the concept to apply both of them.

New request: I would create a new column in the dataset called FREE by using the Price variable. The FREE variable should have the value True if the game is free, and False if the game is not free.

2 Answers

You could do:

 df.query('Name == "PUBG MOBILE"')[['Average.User.Rating','User.Rating.Count']]

For your second request you could try this:

df
         ID     Name  Average.User.Rating  User.Rating.Count
0  23223355   Sudoku                  4.5             300000
1  15115555  Reversi                  3.5             285662                


df['Name'][(df['Average.User.Rating'] >= 4.5) & (df['User.Rating.Count'] >= 300000)]

0    Sudoku

I created a sample data to just apply your desired output, but it is essential to share a reproducible sample as stated by Onyambu's comment:

{'ID': {0: 23223355, 1: 15115555}, 'Name': {0: 'Sudoku', 1: 'Reversi'},
 'Average.User.Rating': {0: 4.5, 1: 3.5}, 'User.Rating.Count': {0: 300000, 1: 285662}}

Updated Answer based on OP's new request:

df['FREE'] = df.apply(lambda x: 'Not Free' if x['Price'] else 'Free', axis = 1)
df

         ID     Name  Average.User.Rating  User.Rating.Count  Price      FREE
0  23223355   Sudoku                  4.5             300000   0.00      Free
1  15115555  Reversi                  3.5             285662   1.25  Not Free
Related