import pandas as pd

films = pd.read_csv("imdb_1000.csv")

print(films)
print(films.columns)
print(films.head())
print(films.tail())
print('----------------------------')
print(films["title"])
print('-----------------------------')
print(films[:9][['title','star_rating']])
print('-----------------------------')

print(films[films['star_rating'] >= 8.5])

print(films[(films['star_rating'] >= 8.5) & (films['star_rating'] <= 9.0)])
"""
    [63 rows x 6 columns]
        star_rating                                              title content_rating      genre  duration                                        actors_list
    3           9.0                                    The Dark Knight          PG-13     Action       152  [u'<NAME>', u'<NAME>', u'<NAME>... 
    4           8.9                                       Pulp Fiction              R      Crime       154  [u'<NAME>', u'<NAME>', u'<NAME>....
    5           8.9                                       12 Angry Men      NOT RATED      Drama        96  [u'<NAME>', u'<NAME>', u'<NAME>...
    6           8.9                     The Good, the Bad and the Ugly      NOT RATED    Western       161  [u'<NAME>', u'<NAME>', u'<NAME> ...
    7           8.9      The Lord of the Rings: The Return of the King          PG-13  Adventure       201  [u'<NAME>', u'<NAME>', u'Ian McK...
    8           8.9                                   Schindler's List              R  Biography       195  [u'<NAME>', u'<NAME>', u'<NAME>...
    9           8.9                                         Fight Club              R      Drama       139  [u'<NAME>', u'<NAME>', u'<NAME>...
    10          8.8  The Lord of the Rings: The Fellowship of the Ring          PG-13  Adventure       178  [u'<NAME>', u'<NAME>', u'Orl<NAME>...
    11          8.8                                          Inception          PG-13     Action       148  [u'<NAME>', u'<NAME>-Levitt'...
    12          8.8     Star Wars: Episode V - The Empire Strikes Back             PG     Action       124  [u'<NAME>', u'<NAME>', u'<NAME>...
    13          8.8                                       Forrest Gump          PG-13      Drama       142    [u'<NAME>', u'<NAME>', u'<NAME>']
    14          8.8              The Lord of the Rings: The Two Towers          PG-13  Adventure       179  [u'<NAME>', u'<NAME>', u'<NAME>...
    15          8.7                                       Interstellar          PG-13  Adventure       169  [u'<NAME>', u'<NAME>', u'J...
    16          8.7                    One Flew Over the Cuckoo's Nest              R      Drama       133  [u'<NAME>', u'<NAME>', u'Mich...
    17          8.7                                      Seven Samurai        UNRATED      Drama       207  [u'Toshir\xf4 Mifune', u'<NAME>', u'K...
    18          8.7                                         Goodfellas              R  Biography       146   [u'<NAME>', u'<NAME>', u'<NAME>']
    19          8.7                                          Star Wars             PG     Action       121  [u'<NAME>', u'<NAME>', u'<NAME>...
    20          8.7                                         The Matrix              R     Action       136  [u'<NAME>', u'<NAME>', u'Car...
    51          8.5                                     Apocalypse Now              R      Drama       153  [u'<NAME>', u'<NAME>', u'<NAME>...
    52          8.5                                 The Great Dictator       APPROVED     Comedy       125  [u'<NAME>', u'<NAME>', u'Ja...
    53          8.5                                       The Prestige          PG-13      Drama       130  [u'<NAME>', u'<NAME>', u'Scarlet...
    54          8.5                                 Back to the Future             PG  Adventure       116  [u'<NAME>', u'<NAME>', u'Le...
    55          8.5                                      The Lion King              G  Animation        89  [u'<NAME>', u'<NAME>', u'Jame...
    56          8.5                                The Lives of Others              R      Drama       137  [u'<NAME>', u'<NAME>', u'Sebas...
    57          8.5                                              Alien              R     Horror       117  [u'Sigourney Weaver', u'<NAME>', u'John ...
    58          8.5                                     Paths of Glory       APPROVED      Drama        88  [u'<NAME>', u'<NAME>', u'Adol<NAME>...
    59          8.5                                   Django Unchained              R    Western       165  [u'<NAME>', u'<NAME>', u'Leonardo...
    60          8.5                                           3 Idiots          PG-13     Comedy       170        [u'<NAME>', u'Madhavan', u'<NAME>']
    61          8.5                             Grave of the Fireflies        UNRATED  Animation        89  [u'<NAME>', u'<NAME>', u'Ake...
    62          8.5                                        The Shining              R     Horror       146  [u'<NAME>', u'<NAME>', u'Danny... 
"""

print("-------------------------------------------------------------------------------------------")
print("\t\t\t\t\tFİLTRELEME - query")

print(films.query('star_rating >= 9.0 & star_rating <= 9.2')
                    [['title','star_rating']])
print("-------------------------------------------------------------------------------------------")

print(films.star_rating.mean())
print(films.groupby('genre').star_rating.mean())
"""
    7.889785495403474
    genre
    Action       7.884559
    Adventure    7.933333
    Animation    7.914516
    Biography    7.862338
    Comedy       7.822436
    Crime        7.916935
    Drama        7.902518
    Family       7.850000
    Fantasy      7.700000
    Film-Noir    8.033333
    History      8.000000
    Horror       7.806897
    Mystery      7.975000
    Sci-Fi       7.920000
    Thriller     7.680000
    Western      8.255556
    Name: star_rating, dtype: float64 
"""

print(films.isnull().head(50))  # NaN mı değil mi?