Home > Software design >  How to find row value for multiple columns using Pandas
How to find row value for multiple columns using Pandas

Time:05-21

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.

CodePudding user response:

You could do:

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

CodePudding user response:

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}}
  • Related