-1

data set

One of my solutions:

import pandas as pd
rating = 'MovieRatings.csv'
data_set=pd.read_csv(r'C:\Users\Korisnik\Documents\dssvol03python\dss03python2023\session02\_data\MovieRatings.csv')
df=pd.DataFrame(data_set,columns=['FILM','Rotten Tomatoes']) 
print(df)
rt=df.sort_values(by=['Rotten Tomatoes'] ['rating'==100])
display(rt)

Always returns Nan

Expected the list of films rated 100 on Rotten tomatoes.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
MashaF
  • 1
  • 2
  • Can you please edit your post to where it clearly states a question – dtthom09 Mar 20 '23 at 18:32
  • 1
    We don't have (and don't need) your CSV file if you follow [how to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/235698) – Mark Tolonen Mar 20 '23 at 18:36
  • Pandas has excellent [documentation on indexing and selecting data](https://pandas.pydata.org/docs/user_guide/indexing.html) that is worth a read-through. Based on what you've shown, you should geta `KeyError`, not a `NaN` output. What is your expectation for what `['rating'==100]` is doing in your code? – G. Anderson Mar 20 '23 at 20:19

2 Answers2

0

It's hard to see what is going on without an example (what does your data look like?), but this should select all rows where the "rating" column is equal to 100.

rt = df[df["rating"] == 100]]

You can combine conditions as well. For example, if you had a "reviewer" column:

mask = (
    (df["rating"] == 100) &
    (df["reviewer] == "Rotten Tomatoes)
)
rt = df[mask]
stressed
  • 328
  • 2
  • 7
0

This is the data set:

                                      FILM  IMDB  Rotten Tomatoes

0 Avengers: Age of Ultron (2015) 7.8 NaN 1 Cinderella (2015) 7.1 NaN 2 Ant-Man (2015) 7.8 NaN 3 Do You Believe? (2015) 5.4 NaN 4 Hot Tub Time Machine 2 (2015) 5.1 NaN .. ... ... ... 141 Mr. Holmes (2015) 7.4 NaN 142 '71 (2015) 7.2 NaN 143 Two Days, One Night (2014) 7.4 NaN 144 Gett: The Trial of Viviane Amsalem (2015) 7.8 NaN 145 Kumiko, The Treasure Hunter (2015) 6.7 NaN

MashaF
  • 1
  • 2
  • Use proper code formatting. This answer is difficult to read. – Donna Mar 25 '23 at 13:38
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Donna Mar 25 '23 at 13:38