python Pandas - 过滤DataFrames和Series
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Pandas - 过滤DataFrames和Series相关的知识,希望对你有一定的参考价值。
import pandas as pd
movies = pd.read_csv('http://bit.ly/imdbratings')
# AND condition
movies[(movies.duration >= 200) & (movies.genre == 'Drama')]
# OR condition
movies[(movies.duration >= 200) | (movies.genre == 'Drama')]
# IN to one or more than one values
movies[movies.genre.isin(['Crime', 'Drama', 'Action'])]
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"movies = pd.read_csv('http://bit.ly/imdbratings')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>9.3</td>\n",
" <td>The Shawshank Redemption</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>142</td>\n",
" <td>[u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>9.2</td>\n",
" <td>The Godfather</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>175</td>\n",
" <td>[u'Marlon Brando', u'Al Pacino', u'James Caan']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>9.0</td>\n",
" <td>The Dark Knight</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>152</td>\n",
" <td>[u'Christian Bale', u'Heath Ledger', u'Aaron E...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8.9</td>\n",
" <td>Pulp Fiction</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>154</td>\n",
" <td>[u'John Travolta', u'Uma Thurman', u'Samuel L....</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" star_rating title content_rating genre duration \\\n",
"0 9.3 The Shawshank Redemption R Crime 142 \n",
"1 9.2 The Godfather R Crime 175 \n",
"2 9.1 The Godfather: Part II R Crime 200 \n",
"3 9.0 The Dark Knight PG-13 Action 152 \n",
"4 8.9 Pulp Fiction R Crime 154 \n",
"\n",
" actors_list \n",
"0 [u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt... \n",
"1 [u'Marlon Brando', u'Al Pacino', u'James Caan'] \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"3 [u'Christian Bale', u'Heath Ledger', u'Aaron E... \n",
"4 [u'John Travolta', u'Uma Thurman', u'Samuel L.... "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies.head()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>8.7</td>\n",
" <td>Seven Samurai</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>207</td>\n",
" <td>[u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>157</th>\n",
" <td>8.2</td>\n",
" <td>Gone with the Wind</td>\n",
" <td>G</td>\n",
" <td>Drama</td>\n",
" <td>238</td>\n",
" <td>[u'Clark Gable', u'Vivien Leigh', u'Thomas Mit...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>476</th>\n",
" <td>7.8</td>\n",
" <td>Hamlet</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>242</td>\n",
" <td>[u'Kenneth Branagh', u'Julie Christie', u'Dere...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" star_rating title content_rating genre duration \\\n",
"17 8.7 Seven Samurai UNRATED Drama 207 \n",
"157 8.2 Gone with the Wind G Drama 238 \n",
"476 7.8 Hamlet PG-13 Drama 242 \n",
"\n",
" actors_list \n",
"17 [u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K... \n",
"157 [u'Clark Gable', u'Vivien Leigh', u'Thomas Mit... \n",
"476 [u'Kenneth Branagh', u'Julie Christie', u'Dere... "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies[(movies.duration >= 200) & (movies.genre == 'Drama')]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>8.9</td>\n",
" <td>12 Angry Men</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>96</td>\n",
" <td>[u'Henry Fonda', u'Lee J. Cobb', u'Martin Bals...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8.9</td>\n",
" <td>The Lord of the Rings: The Return of the King</td>\n",
" <td>PG-13</td>\n",
" <td>Adventure</td>\n",
" <td>201</td>\n",
" <td>[u'Elijah Wood', u'Viggo Mortensen', u'Ian McK...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>8.9</td>\n",
" <td>Fight Club</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>139</td>\n",
" <td>[u'Brad Pitt', u'Edward Norton', u'Helena Bonh...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>8.8</td>\n",
" <td>Forrest Gump</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>142</td>\n",
" <td>[u'Tom Hanks', u'Robin Wright', u'Gary Sinise']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>8.7</td>\n",
" <td>One Flew Over the Cuckoo's Nest</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>133</td>\n",
" <td>[u'Jack Nicholson', u'Louise Fletcher', u'Mich...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>8.7</td>\n",
" <td>Seven Samurai</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>207</td>\n",
" <td>[u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>8.7</td>\n",
" <td>It's a Wonderful Life</td>\n",
" <td>APPROVED</td>\n",
" <td>Drama</td>\n",
" <td>130</td>\n",
" <td>[u'James Stewart', u'Donna Reed', u'Lionel Bar...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>8.7</td>\n",
" <td>Se7en</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>127</td>\n",
" <td>[u'Morgan Freeman', u'Brad Pitt', u'Kevin Spac...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>8.6</td>\n",
" <td>The Silence of the Lambs</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>118</td>\n",
" <td>[u'Jodie Foster', u'Anthony Hopkins', u'Lawren...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>8.6</td>\n",
" <td>Casablanca</td>\n",
" <td>PG</td>\n",
" <td>Drama</td>\n",
" <td>102</td>\n",
" <td>[u'Humphrey Bogart', u'Ingrid Bergman', u'Paul...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>8.6</td>\n",
" <td>Whiplash</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Miles Teller', u'J.K. Simmons', u'Melissa B...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>8.5</td>\n",
" <td>Sunset Blvd.</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>110</td>\n",
" <td>[u'William Holden', u'Gloria Swanson', u'Erich...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>8.5</td>\n",
" <td>Taare Zameen Par</td>\n",
" <td>PG</td>\n",
" <td>Drama</td>\n",
" <td>165</td>\n",
" <td>[u'Darsheel Safary', u'Aamir Khan', u'Tanay Ch...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>8.5</td>\n",
" <td>Cinema Paradiso</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>155</td>\n",
" <td>[u'Philippe Noiret', u'Enzo Cannavale', u'Anto...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>8.5</td>\n",
" <td>Apocalypse Now</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>153</td>\n",
" <td>[u'Martin Sheen', u'Marlon Brando', u'Robert D...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>8.5</td>\n",
" <td>The Prestige</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>130</td>\n",
" <td>[u'Christian Bale', u'Hugh Jackman', u'Scarlet...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>56</th>\n",
" <td>8.5</td>\n",
" <td>The Lives of Others</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>137</td>\n",
" <td>[u'Ulrich M\\xfche', u'Martina Gedeck', u'Sebas...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58</th>\n",
" <td>8.5</td>\n",
" <td>Paths of Glory</td>\n",
" <td>APPROVED</td>\n",
" <td>Drama</td>\n",
" <td>88</td>\n",
" <td>[u'Kirk Douglas', u'Ralph Meeker', u'Adolphe M...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>67</th>\n",
" <td>8.4</td>\n",
" <td>American Beauty</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>122</td>\n",
" <td>[u'Kevin Spacey', u'Annette Bening', u'Thora B...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>72</th>\n",
" <td>8.4</td>\n",
" <td>Rang De Basanti</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>157</td>\n",
" <td>[u'Aamir Khan', u'Soha Ali Khan', u'Siddharth']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>73</th>\n",
" <td>8.4</td>\n",
" <td>Jodaeiye Nader az Simin</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>123</td>\n",
" <td>[u'Peyman Moaadi', u'Leila Hatami', u'Sareh Ba...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>8.4</td>\n",
" <td>Citizen Kane</td>\n",
" <td>APPROVED</td>\n",
" <td>Drama</td>\n",
" <td>119</td>\n",
" <td>[u'Orson Welles', u'Joseph Cotten', u'Dorothy ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>77</th>\n",
" <td>8.4</td>\n",
" <td>Oldeuboi</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>120</td>\n",
" <td>[u'Min-sik Choi', u'Ji-tae Yu', u'Hye-jeong Ka...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>8.4</td>\n",
" <td>Once Upon a Time in America</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>229</td>\n",
" <td>[u'Robert De Niro', u'James Woods', u'Elizabet...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>8.4</td>\n",
" <td>To Kill a Mockingbird</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>129</td>\n",
" <td>[u'Gregory Peck', u'John Megna', u'Frank Overt...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>8.4</td>\n",
" <td>Requiem for a Dream</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>102</td>\n",
" <td>[u'Ellen Burstyn', u'Jared Leto', u'Jennifer C...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>8.4</td>\n",
" <td>Lawrence of Arabia</td>\n",
" <td>PG</td>\n",
" <td>Adventure</td>\n",
" <td>216</td>\n",
" <td>[u\"Peter O'Toole\", u'Alec Guinness', u'Anthony...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>87</th>\n",
" <td>8.4</td>\n",
" <td>Bicycle Thieves</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>93</td>\n",
" <td>[u'Lamberto Maggiorani', u'Enzo Staiola', u'Li...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>8.4</td>\n",
" <td>Swades</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>189</td>\n",
" <td>[u'Shah Rukh Khan', u'Gayatri Joshi', u'Kishor...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>875</th>\n",
" <td>7.5</td>\n",
" <td>Rust and Bone</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>120</td>\n",
" <td>[u'Marion Cotillard', u'Matthias Schoenaerts',...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>877</th>\n",
" <td>7.5</td>\n",
" <td>Legends of the Fall</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>133</td>\n",
" <td>[u'Brad Pitt', u'Anthony Hopkins', u'Aidan Qui...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>879</th>\n",
" <td>7.5</td>\n",
" <td>The Constant Gardener</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>129</td>\n",
" <td>[u'Ralph Fiennes', u'Rachel Weisz', u'Hubert K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>886</th>\n",
" <td>7.5</td>\n",
" <td>Pi</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>84</td>\n",
" <td>[u'Sean Gullette', u'Mark Margolis', u'Ben She...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>887</th>\n",
" <td>7.5</td>\n",
" <td>The Devil's Backbone</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>106</td>\n",
" <td>[u'Marisa Paredes', u'Eduardo Noriega', u'Fede...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>889</th>\n",
" <td>7.5</td>\n",
" <td>Devil's Advocate</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>144</td>\n",
" <td>[u'Keanu Reeves', u'Al Pacino', u'Charlize The...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>895</th>\n",
" <td>7.5</td>\n",
" <td>Biutiful</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>148</td>\n",
" <td>[u'Javier Bardem', u'Maricel \\xc1lvarez', u'Ha...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>897</th>\n",
" <td>7.5</td>\n",
" <td>Calvary</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>102</td>\n",
" <td>[u'Brendan Gleeson', u\"Chris O'Dowd\", u'Kelly ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>901</th>\n",
" <td>7.5</td>\n",
" <td>Babel</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>143</td>\n",
" <td>[u'Brad Pitt', u'Cate Blanchett', u'Gael Garc\\...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>904</th>\n",
" <td>7.5</td>\n",
" <td>Sweeney Todd: The Demon Barber of Fleet Street</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>116</td>\n",
" <td>[u'Johnny Depp', u'Helena Bonham Carter', u'Al...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>910</th>\n",
" <td>7.5</td>\n",
" <td>2046</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>129</td>\n",
" <td>[u'Tony Chiu Wai Leung', u'Ziyi Zhang', u'Faye...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>914</th>\n",
" <td>7.5</td>\n",
" <td>The Judge</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>141</td>\n",
" <td>[u'Robert Downey Jr.', u'Robert Duvall', u'Ver...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>916</th>\n",
" <td>7.5</td>\n",
" <td>Up in the Air</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>109</td>\n",
" <td>[u'George Clooney', u'Vera Farmiga', u'Anna Ke...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>917</th>\n",
" <td>7.5</td>\n",
" <td>Begin Again</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>104</td>\n",
" <td>[u'Keira Knightley', u'Mark Ruffalo', u'Adam L...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>922</th>\n",
" <td>7.5</td>\n",
" <td>Mud</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>130</td>\n",
" <td>[u'Matthew McConaughey', u'Tye Sheridan', u'Ja...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>923</th>\n",
" <td>7.5</td>\n",
" <td>Across the Universe</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>133</td>\n",
" <td>[u'Evan Rachel Wood', u'Jim Sturgess', u'Joe A...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>925</th>\n",
" <td>7.5</td>\n",
" <td>Notes on a Scandal</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>92</td>\n",
" <td>[u'Cate Blanchett', u'Judi Dench', u'Andrew Si...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>926</th>\n",
" <td>7.5</td>\n",
" <td>Inside Llewyn Davis</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>104</td>\n",
" <td>[u'Oscar Isaac', u'Carey Mulligan', u'John Goo...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>939</th>\n",
" <td>7.4</td>\n",
" <td>Predestination</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>97</td>\n",
" <td>[u'Ethan Hawke', u'Sarah Snook', u'Noah Taylor']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>941</th>\n",
" <td>7.4</td>\n",
" <td>A Bridge Too Far</td>\n",
" <td>PG</td>\n",
" <td>Drama</td>\n",
" <td>175</td>\n",
" <td>[u'Sean Connery', u\"Ryan O'Neal\", u'Michael Ca...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>945</th>\n",
" <td>7.4</td>\n",
" <td>Take Shelter</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>120</td>\n",
" <td>[u'Michael Shannon', u'Jessica Chastain', u'Sh...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>946</th>\n",
" <td>7.4</td>\n",
" <td>Far from Heaven</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Julianne Moore', u'Dennis Quaid', u'Dennis ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>947</th>\n",
" <td>7.4</td>\n",
" <td>Eraserhead</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>89</td>\n",
" <td>[u'Jack Nance', u'Charlotte Stewart', u'Allen ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>951</th>\n",
" <td>7.4</td>\n",
" <td>Sleepy Hollow</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>105</td>\n",
" <td>[u'Johnny Depp', u'Christina Ricci', u'Miranda...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>955</th>\n",
" <td>7.4</td>\n",
" <td>Zero Dark Thirty</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>157</td>\n",
" <td>[u'Jessica Chastain', u'Joel Edgerton', u'Chri...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>958</th>\n",
" <td>7.4</td>\n",
" <td>My Sister's Keeper</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>109</td>\n",
" <td>[u'Cameron Diaz', u'Abigail Breslin', u'Alec B...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>968</th>\n",
" <td>7.4</td>\n",
" <td>The English Patient</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>162</td>\n",
" <td>[u'Ralph Fiennes', u'Juliette Binoche', u'Will...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>970</th>\n",
" <td>7.4</td>\n",
" <td>Wonder Boys</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Michael Douglas', u'Tobey Maguire', u'Franc...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>972</th>\n",
" <td>7.4</td>\n",
" <td>Blue Valentine</td>\n",
" <td>NC-17</td>\n",
" <td>Drama</td>\n",
" <td>112</td>\n",
" <td>[u'Ryan Gosling', u'Michelle Williams', u'John...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>973</th>\n",
" <td>7.4</td>\n",
" <td>The Cider House Rules</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>126</td>\n",
" <td>[u'Tobey Maguire', u'Charlize Theron', u'Micha...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>287 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" star_rating title \\\n",
"2 9.1 The Godfather: Part II \n",
"5 8.9 12 Angry Men \n",
"7 8.9 The Lord of the Rings: The Return of the King \n",
"9 8.9 Fight Club \n",
"13 8.8 Forrest Gump \n",
"16 8.7 One Flew Over the Cuckoo's Nest \n",
"17 8.7 Seven Samurai \n",
"22 8.7 It's a Wonderful Life \n",
"24 8.7 Se7en \n",
"27 8.6 The Silence of the Lambs \n",
"32 8.6 Casablanca \n",
"33 8.6 Whiplash \n",
"41 8.5 Sunset Blvd. \n",
"47 8.5 Taare Zameen Par \n",
"50 8.5 Cinema Paradiso \n",
"51 8.5 Apocalypse Now \n",
"53 8.5 The Prestige \n",
"56 8.5 The Lives of Others \n",
"58 8.5 Paths of Glory \n",
"67 8.4 American Beauty \n",
"72 8.4 Rang De Basanti \n",
"73 8.4 Jodaeiye Nader az Simin \n",
"74 8.4 Citizen Kane \n",
"77 8.4 Oldeuboi \n",
"78 8.4 Once Upon a Time in America \n",
"83 8.4 To Kill a Mockingbird \n",
"84 8.4 Requiem for a Dream \n",
"85 8.4 Lawrence of Arabia \n",
"87 8.4 Bicycle Thieves \n",
"89 8.4 Swades \n",
".. ... ... \n",
"875 7.5 Rust and Bone \n",
"877 7.5 Legends of the Fall \n",
"879 7.5 The Constant Gardener \n",
"886 7.5 Pi \n",
"887 7.5 The Devil's Backbone \n",
"889 7.5 Devil's Advocate \n",
"895 7.5 Biutiful \n",
"897 7.5 Calvary \n",
"901 7.5 Babel \n",
"904 7.5 Sweeney Todd: The Demon Barber of Fleet Street \n",
"910 7.5 2046 \n",
"914 7.5 The Judge \n",
"916 7.5 Up in the Air \n",
"917 7.5 Begin Again \n",
"922 7.5 Mud \n",
"923 7.5 Across the Universe \n",
"925 7.5 Notes on a Scandal \n",
"926 7.5 Inside Llewyn Davis \n",
"939 7.4 Predestination \n",
"941 7.4 A Bridge Too Far \n",
"945 7.4 Take Shelter \n",
"946 7.4 Far from Heaven \n",
"947 7.4 Eraserhead \n",
"951 7.4 Sleepy Hollow \n",
"955 7.4 Zero Dark Thirty \n",
"958 7.4 My Sister's Keeper \n",
"968 7.4 The English Patient \n",
"970 7.4 Wonder Boys \n",
"972 7.4 Blue Valentine \n",
"973 7.4 The Cider House Rules \n",
"\n",
" content_rating genre duration \\\n",
"2 R Crime 200 \n",
"5 NOT RATED Drama 96 \n",
"7 PG-13 Adventure 201 \n",
"9 R Drama 139 \n",
"13 PG-13 Drama 142 \n",
"16 R Drama 133 \n",
"17 UNRATED Drama 207 \n",
"22 APPROVED Drama 130 \n",
"24 R Drama 127 \n",
"27 R Drama 118 \n",
"32 PG Drama 102 \n",
"33 R Drama 107 \n",
"41 NOT RATED Drama 110 \n",
"47 PG Drama 165 \n",
"50 R Drama 155 \n",
"51 R Drama 153 \n",
"53 PG-13 Drama 130 \n",
"56 R Drama 137 \n",
"58 APPROVED Drama 88 \n",
"67 R Drama 122 \n",
"72 NOT RATED Drama 157 \n",
"73 PG-13 Drama 123 \n",
"74 APPROVED Drama 119 \n",
"77 R Drama 120 \n",
"78 R Crime 229 \n",
"83 NOT RATED Drama 129 \n",
"84 R Drama 102 \n",
"85 PG Adventure 216 \n",
"87 NOT RATED Drama 93 \n",
"89 NOT RATED Drama 189 \n",
".. ... ... ... \n",
"875 R Drama 120 \n",
"877 R Drama 133 \n",
"879 R Drama 129 \n",
"886 R Drama 84 \n",
"887 R Drama 106 \n",
"889 R Drama 144 \n",
"895 R Drama 148 \n",
"897 R Drama 102 \n",
"901 R Drama 143 \n",
"904 R Drama 116 \n",
"910 R Drama 129 \n",
"914 R Drama 141 \n",
"916 R Drama 109 \n",
"917 R Drama 104 \n",
"922 PG-13 Drama 130 \n",
"923 PG-13 Drama 133 \n",
"925 R Drama 92 \n",
"926 R Drama 104 \n",
"939 R Drama 97 \n",
"941 PG Drama 175 \n",
"945 R Drama 120 \n",
"946 PG-13 Drama 107 \n",
"947 UNRATED Drama 89 \n",
"951 R Drama 105 \n",
"955 R Drama 157 \n",
"958 PG-13 Drama 109 \n",
"968 R Drama 162 \n",
"970 R Drama 107 \n",
"972 NC-17 Drama 112 \n",
"973 PG-13 Drama 126 \n",
"\n",
" actors_list \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"5 [u'Henry Fonda', u'Lee J. Cobb', u'Martin Bals... \n",
"7 [u'Elijah Wood', u'Viggo Mortensen', u'Ian McK... \n",
"9 [u'Brad Pitt', u'Edward Norton', u'Helena Bonh... \n",
"13 [u'Tom Hanks', u'Robin Wright', u'Gary Sinise'] \n",
"16 [u'Jack Nicholson', u'Louise Fletcher', u'Mich... \n",
"17 [u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K... \n",
"22 [u'James Stewart', u'Donna Reed', u'Lionel Bar... \n",
"24 [u'Morgan Freeman', u'Brad Pitt', u'Kevin Spac... \n",
"27 [u'Jodie Foster', u'Anthony Hopkins', u'Lawren... \n",
"32 [u'Humphrey Bogart', u'Ingrid Bergman', u'Paul... \n",
"33 [u'Miles Teller', u'J.K. Simmons', u'Melissa B... \n",
"41 [u'William Holden', u'Gloria Swanson', u'Erich... \n",
"47 [u'Darsheel Safary', u'Aamir Khan', u'Tanay Ch... \n",
"50 [u'Philippe Noiret', u'Enzo Cannavale', u'Anto... \n",
"51 [u'Martin Sheen', u'Marlon Brando', u'Robert D... \n",
"53 [u'Christian Bale', u'Hugh Jackman', u'Scarlet... \n",
"56 [u'Ulrich M\\xfche', u'Martina Gedeck', u'Sebas... \n",
"58 [u'Kirk Douglas', u'Ralph Meeker', u'Adolphe M... \n",
"67 [u'Kevin Spacey', u'Annette Bening', u'Thora B... \n",
"72 [u'Aamir Khan', u'Soha Ali Khan', u'Siddharth'] \n",
"73 [u'Peyman Moaadi', u'Leila Hatami', u'Sareh Ba... \n",
"74 [u'Orson Welles', u'Joseph Cotten', u'Dorothy ... \n",
"77 [u'Min-sik Choi', u'Ji-tae Yu', u'Hye-jeong Ka... \n",
"78 [u'Robert De Niro', u'James Woods', u'Elizabet... \n",
"83 [u'Gregory Peck', u'John Megna', u'Frank Overt... \n",
"84 [u'Ellen Burstyn', u'Jared Leto', u'Jennifer C... \n",
"85 [u\"Peter O'Toole\", u'Alec Guinness', u'Anthony... \n",
"87 [u'Lamberto Maggiorani', u'Enzo Staiola', u'Li... \n",
"89 [u'Shah Rukh Khan', u'Gayatri Joshi', u'Kishor... \n",
".. ... \n",
"875 [u'Marion Cotillard', u'Matthias Schoenaerts',... \n",
"877 [u'Brad Pitt', u'Anthony Hopkins', u'Aidan Qui... \n",
"879 [u'Ralph Fiennes', u'Rachel Weisz', u'Hubert K... \n",
"886 [u'Sean Gullette', u'Mark Margolis', u'Ben She... \n",
"887 [u'Marisa Paredes', u'Eduardo Noriega', u'Fede... \n",
"889 [u'Keanu Reeves', u'Al Pacino', u'Charlize The... \n",
"895 [u'Javier Bardem', u'Maricel \\xc1lvarez', u'Ha... \n",
"897 [u'Brendan Gleeson', u\"Chris O'Dowd\", u'Kelly ... \n",
"901 [u'Brad Pitt', u'Cate Blanchett', u'Gael Garc\\... \n",
"904 [u'Johnny Depp', u'Helena Bonham Carter', u'Al... \n",
"910 [u'Tony Chiu Wai Leung', u'Ziyi Zhang', u'Faye... \n",
"914 [u'Robert Downey Jr.', u'Robert Duvall', u'Ver... \n",
"916 [u'George Clooney', u'Vera Farmiga', u'Anna Ke... \n",
"917 [u'Keira Knightley', u'Mark Ruffalo', u'Adam L... \n",
"922 [u'Matthew McConaughey', u'Tye Sheridan', u'Ja... \n",
"923 [u'Evan Rachel Wood', u'Jim Sturgess', u'Joe A... \n",
"925 [u'Cate Blanchett', u'Judi Dench', u'Andrew Si... \n",
"926 [u'Oscar Isaac', u'Carey Mulligan', u'John Goo... \n",
"939 [u'Ethan Hawke', u'Sarah Snook', u'Noah Taylor'] \n",
"941 [u'Sean Connery', u\"Ryan O'Neal\", u'Michael Ca... \n",
"945 [u'Michael Shannon', u'Jessica Chastain', u'Sh... \n",
"946 [u'Julianne Moore', u'Dennis Quaid', u'Dennis ... \n",
"947 [u'Jack Nance', u'Charlotte Stewart', u'Allen ... \n",
"951 [u'Johnny Depp', u'Christina Ricci', u'Miranda... \n",
"955 [u'Jessica Chastain', u'Joel Edgerton', u'Chri... \n",
"958 [u'Cameron Diaz', u'Abigail Breslin', u'Alec B... \n",
"968 [u'Ralph Fiennes', u'Juliette Binoche', u'Will... \n",
"970 [u'Michael Douglas', u'Tobey Maguire', u'Franc... \n",
"972 [u'Ryan Gosling', u'Michelle Williams', u'John... \n",
"973 [u'Tobey Maguire', u'Charlize Theron', u'Micha... \n",
"\n",
"[287 rows x 6 columns]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies[(movies.duration >= 200) | (movies.genre == 'Drama')]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>9.3</td>\n",
" <td>The Shawshank Redemption</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>142</td>\n",
" <td>[u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>9.2</td>\n",
" <td>The Godfather</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>175</td>\n",
" <td>[u'Marlon Brando', u'Al Pacino', u'James Caan']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>9.0</td>\n",
" <td>The Dark Knight</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>152</td>\n",
" <td>[u'Christian Bale', u'Heath Ledger', u'Aaron E...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8.9</td>\n",
" <td>Pulp Fiction</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>154</td>\n",
" <td>[u'John Travolta', u'Uma Thurman', u'Samuel L....</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>8.9</td>\n",
" <td>12 Angry Men</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>96</td>\n",
" <td>[u'Henry Fonda', u'Lee J. Cobb', u'Martin Bals...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>8.9</td>\n",
" <td>Fight Club</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>139</td>\n",
" <td>[u'Brad Pitt', u'Edward Norton', u'Helena Bonh...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>8.8</td>\n",
" <td>Inception</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>148</td>\n",
" <td>[u'Leonardo DiCaprio', u'Joseph Gordon-Levitt'...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>8.8</td>\n",
" <td>Star Wars: Episode V - The Empire Strikes Back</td>\n",
" <td>PG</td>\n",
" <td>Action</td>\n",
" <td>124</td>\n",
" <td>[u'Mark Hamill', u'Harrison Ford', u'Carrie Fi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>8.8</td>\n",
" <td>Forrest Gump</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>142</td>\n",
" <td>[u'Tom Hanks', u'Robin Wright', u'Gary Sinise']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>8.7</td>\n",
" <td>One Flew Over the Cuckoo's Nest</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>133</td>\n",
" <td>[u'Jack Nicholson', u'Louise Fletcher', u'Mich...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>8.7</td>\n",
" <td>Seven Samurai</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>207</td>\n",
" <td>[u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>8.7</td>\n",
" <td>Star Wars</td>\n",
" <td>PG</td>\n",
" <td>Action</td>\n",
" <td>121</td>\n",
" <td>[u'Mark Hamill', u'Harrison Ford', u'Carrie Fi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>8.7</td>\n",
" <td>The Matrix</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>136</td>\n",
" <td>[u'Keanu Reeves', u'Laurence Fishburne', u'Car...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>8.7</td>\n",
" <td>City of God</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>130</td>\n",
" <td>[u'Alexandre Rodrigues', u'Matheus Nachtergael...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>8.7</td>\n",
" <td>It's a Wonderful Life</td>\n",
" <td>APPROVED</td>\n",
" <td>Drama</td>\n",
" <td>130</td>\n",
" <td>[u'James Stewart', u'Donna Reed', u'Lionel Bar...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>8.7</td>\n",
" <td>The Usual Suspects</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>106</td>\n",
" <td>[u'Kevin Spacey', u'Gabriel Byrne', u'Chazz Pa...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>8.7</td>\n",
" <td>Se7en</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>127</td>\n",
" <td>[u'Morgan Freeman', u'Brad Pitt', u'Kevin Spac...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>8.6</td>\n",
" <td>The Silence of the Lambs</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>118</td>\n",
" <td>[u'Jodie Foster', u'Anthony Hopkins', u'Lawren...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>8.6</td>\n",
" <td>Leon: The Professional</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>110</td>\n",
" <td>[u'Jean Reno', u'Gary Oldman', u'Natalie Portm...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>8.6</td>\n",
" <td>Casablanca</td>\n",
" <td>PG</td>\n",
" <td>Drama</td>\n",
" <td>102</td>\n",
" <td>[u'Humphrey Bogart', u'Ingrid Bergman', u'Paul...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>8.6</td>\n",
" <td>Whiplash</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Miles Teller', u'J.K. Simmons', u'Melissa B...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>8.6</td>\n",
" <td>American History X</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>119</td>\n",
" <td>[u'Edward Norton', u'Edward Furlong', u\"Beverl...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>8.6</td>\n",
" <td>Saving Private Ryan</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>169</td>\n",
" <td>[u'Tom Hanks', u'Matt Damon', u'Tom Sizemore']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>8.6</td>\n",
" <td>Raiders of the Lost Ark</td>\n",
" <td>PG</td>\n",
" <td>Action</td>\n",
" <td>115</td>\n",
" <td>[u'Harrison Ford', u'Karen Allen', u'Paul Free...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>8.5</td>\n",
" <td>The Green Mile</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>189</td>\n",
" <td>[u'Tom Hanks', u'Michael Clarke Duncan', u'Dav...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>8.5</td>\n",
" <td>Sunset Blvd.</td>\n",
" <td>NOT RATED</td>\n",
" <td>Drama</td>\n",
" <td>110</td>\n",
" <td>[u'William Holden', u'Gloria Swanson', u'Erich...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>8.5</td>\n",
" <td>The Dark Knight Rises</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>165</td>\n",
" <td>[u'Christian Bale', u'Tom Hardy', u'Anne Hatha...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>8.5</td>\n",
" <td>Gladiator</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>155</td>\n",
" <td>[u'Russell Crowe', u'Joaquin Phoenix', u'Conni...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>8.5</td>\n",
" <td>Terminator 2: Judgment Day</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>137</td>\n",
" <td>[u'Arnold Schwarzenegger', u'Linda Hamilton', ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>916</th>\n",
" <td>7.5</td>\n",
" <td>Up in the Air</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>109</td>\n",
" <td>[u'George Clooney', u'Vera Farmiga', u'Anna Ke...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>917</th>\n",
" <td>7.5</td>\n",
" <td>Begin Again</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>104</td>\n",
" <td>[u'Keira Knightley', u'Mark Ruffalo', u'Adam L...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>918</th>\n",
" <td>7.5</td>\n",
" <td>Running Scared</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>122</td>\n",
" <td>[u'Paul Walker', u'Cameron Bright', u'Chazz Pa...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>920</th>\n",
" <td>7.5</td>\n",
" <td>Witness</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>112</td>\n",
" <td>[u'Harrison Ford', u'Kelly McGillis', u'Lukas ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>922</th>\n",
" <td>7.5</td>\n",
" <td>Mud</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>130</td>\n",
" <td>[u'Matthew McConaughey', u'Tye Sheridan', u'Ja...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>923</th>\n",
" <td>7.5</td>\n",
" <td>Across the Universe</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>133</td>\n",
" <td>[u'Evan Rachel Wood', u'Jim Sturgess', u'Joe A...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>924</th>\n",
" <td>7.5</td>\n",
" <td>Les Miserables</td>\n",
" <td>PG-13</td>\n",
" <td>Crime</td>\n",
" <td>134</td>\n",
" <td>[u'Liam Neeson', u'Geoffrey Rush', u'Uma Thurm...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>925</th>\n",
" <td>7.5</td>\n",
" <td>Notes on a Scandal</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>92</td>\n",
" <td>[u'Cate Blanchett', u'Judi Dench', u'Andrew Si...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>926</th>\n",
" <td>7.5</td>\n",
" <td>Inside Llewyn Davis</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>104</td>\n",
" <td>[u'Oscar Isaac', u'Carey Mulligan', u'John Goo...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>927</th>\n",
" <td>7.5</td>\n",
" <td>Brick</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>110</td>\n",
" <td>[u'Joseph Gordon-Levitt', u'Lukas Haas', u'Emi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>931</th>\n",
" <td>7.4</td>\n",
" <td>Mean Streets</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>112</td>\n",
" <td>[u'Robert De Niro', u'Harvey Keitel', u'David ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>939</th>\n",
" <td>7.4</td>\n",
" <td>Predestination</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>97</td>\n",
" <td>[u'Ethan Hawke', u'Sarah Snook', u'Noah Taylor']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>941</th>\n",
" <td>7.4</td>\n",
" <td>A Bridge Too Far</td>\n",
" <td>PG</td>\n",
" <td>Drama</td>\n",
" <td>175</td>\n",
" <td>[u'Sean Connery', u\"Ryan O'Neal\", u'Michael Ca...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>945</th>\n",
" <td>7.4</td>\n",
" <td>Take Shelter</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>120</td>\n",
" <td>[u'Michael Shannon', u'Jessica Chastain', u'Sh...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>946</th>\n",
" <td>7.4</td>\n",
" <td>Far from Heaven</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Julianne Moore', u'Dennis Quaid', u'Dennis ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>947</th>\n",
" <td>7.4</td>\n",
" <td>Eraserhead</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>89</td>\n",
" <td>[u'Jack Nance', u'Charlotte Stewart', u'Allen ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>950</th>\n",
" <td>7.4</td>\n",
" <td>Bound</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>108</td>\n",
" <td>[u'Jennifer Tilly', u'Gina Gershon', u'Joe Pan...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>951</th>\n",
" <td>7.4</td>\n",
" <td>Sleepy Hollow</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>105</td>\n",
" <td>[u'Johnny Depp', u'Christina Ricci', u'Miranda...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>954</th>\n",
" <td>7.4</td>\n",
" <td>X-Men</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>104</td>\n",
" <td>[u'Patrick Stewart', u'Hugh Jackman', u'Ian Mc...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>955</th>\n",
" <td>7.4</td>\n",
" <td>Zero Dark Thirty</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>157</td>\n",
" <td>[u'Jessica Chastain', u'Joel Edgerton', u'Chri...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>958</th>\n",
" <td>7.4</td>\n",
" <td>My Sister's Keeper</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>109</td>\n",
" <td>[u'Cameron Diaz', u'Abigail Breslin', u'Alec B...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>963</th>\n",
" <td>7.4</td>\n",
" <td>La Femme Nikita</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>118</td>\n",
" <td>[u'Anne Parillaud', u'Marc Duret', u'Patrick F...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>967</th>\n",
" <td>7.4</td>\n",
" <td>The Rock</td>\n",
" <td>R</td>\n",
" <td>Action</td>\n",
" <td>136</td>\n",
" <td>[u'Sean Connery', u'Nicolas Cage', u'Ed Harris']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>968</th>\n",
" <td>7.4</td>\n",
" <td>The English Patient</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>162</td>\n",
" <td>[u'Ralph Fiennes', u'Juliette Binoche', u'Will...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>969</th>\n",
" <td>7.4</td>\n",
" <td>Law Abiding Citizen</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>109</td>\n",
" <td>[u'Gerard Butler', u'Jamie Foxx', u'Leslie Bibb']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>970</th>\n",
" <td>7.4</td>\n",
" <td>Wonder Boys</td>\n",
" <td>R</td>\n",
" <td>Drama</td>\n",
" <td>107</td>\n",
" <td>[u'Michael Douglas', u'Tobey Maguire', u'Franc...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>972</th>\n",
" <td>7.4</td>\n",
" <td>Blue Valentine</td>\n",
" <td>NC-17</td>\n",
" <td>Drama</td>\n",
" <td>112</td>\n",
" <td>[u'Ryan Gosling', u'Michelle Williams', u'John...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>973</th>\n",
" <td>7.4</td>\n",
" <td>The Cider House Rules</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>126</td>\n",
" <td>[u'Tobey Maguire', u'Charlize Theron', u'Micha...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>976</th>\n",
" <td>7.4</td>\n",
" <td>Master and Commander: The Far Side of the World</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>138</td>\n",
" <td>[u'Russell Crowe', u'Paul Bettany', u'Billy Bo...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>978</th>\n",
" <td>7.4</td>\n",
" <td>Wall Street</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>126</td>\n",
" <td>[u'Charlie Sheen', u'Michael Douglas', u'Tamar...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>538 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" star_rating title \\\n",
"0 9.3 The Shawshank Redemption \n",
"1 9.2 The Godfather \n",
"2 9.1 The Godfather: Part II \n",
"3 9.0 The Dark Knight \n",
"4 8.9 Pulp Fiction \n",
"5 8.9 12 Angry Men \n",
"9 8.9 Fight Club \n",
"11 8.8 Inception \n",
"12 8.8 Star Wars: Episode V - The Empire Strikes Back \n",
"13 8.8 Forrest Gump \n",
"16 8.7 One Flew Over the Cuckoo's Nest \n",
"17 8.7 Seven Samurai \n",
"19 8.7 Star Wars \n",
"20 8.7 The Matrix \n",
"21 8.7 City of God \n",
"22 8.7 It's a Wonderful Life \n",
"23 8.7 The Usual Suspects \n",
"24 8.7 Se7en \n",
"27 8.6 The Silence of the Lambs \n",
"28 8.6 Leon: The Professional \n",
"32 8.6 Casablanca \n",
"33 8.6 Whiplash \n",
"34 8.6 American History X \n",
"36 8.6 Saving Private Ryan \n",
"37 8.6 Raiders of the Lost Ark \n",
"40 8.5 The Green Mile \n",
"41 8.5 Sunset Blvd. \n",
"43 8.5 The Dark Knight Rises \n",
"44 8.5 Gladiator \n",
"45 8.5 Terminator 2: Judgment Day \n",
".. ... ... \n",
"916 7.5 Up in the Air \n",
"917 7.5 Begin Again \n",
"918 7.5 Running Scared \n",
"920 7.5 Witness \n",
"922 7.5 Mud \n",
"923 7.5 Across the Universe \n",
"924 7.5 Les Miserables \n",
"925 7.5 Notes on a Scandal \n",
"926 7.5 Inside Llewyn Davis \n",
"927 7.5 Brick \n",
"931 7.4 Mean Streets \n",
"939 7.4 Predestination \n",
"941 7.4 A Bridge Too Far \n",
"945 7.4 Take Shelter \n",
"946 7.4 Far from Heaven \n",
"947 7.4 Eraserhead \n",
"950 7.4 Bound \n",
"951 7.4 Sleepy Hollow \n",
"954 7.4 X-Men \n",
"955 7.4 Zero Dark Thirty \n",
"958 7.4 My Sister's Keeper \n",
"963 7.4 La Femme Nikita \n",
"967 7.4 The Rock \n",
"968 7.4 The English Patient \n",
"969 7.4 Law Abiding Citizen \n",
"970 7.4 Wonder Boys \n",
"972 7.4 Blue Valentine \n",
"973 7.4 The Cider House Rules \n",
"976 7.4 Master and Commander: The Far Side of the World \n",
"978 7.4 Wall Street \n",
"\n",
" content_rating genre duration \\\n",
"0 R Crime 142 \n",
"1 R Crime 175 \n",
"2 R Crime 200 \n",
"3 PG-13 Action 152 \n",
"4 R Crime 154 \n",
"5 NOT RATED Drama 96 \n",
"9 R Drama 139 \n",
"11 PG-13 Action 148 \n",
"12 PG Action 124 \n",
"13 PG-13 Drama 142 \n",
"16 R Drama 133 \n",
"17 UNRATED Drama 207 \n",
"19 PG Action 121 \n",
"20 R Action 136 \n",
"21 R Crime 130 \n",
"22 APPROVED Drama 130 \n",
"23 R Crime 106 \n",
"24 R Drama 127 \n",
"27 R Drama 118 \n",
"28 R Crime 110 \n",
"32 PG Drama 102 \n",
"33 R Drama 107 \n",
"34 R Crime 119 \n",
"36 R Action 169 \n",
"37 PG Action 115 \n",
"40 R Crime 189 \n",
"41 NOT RATED Drama 110 \n",
"43 PG-13 Action 165 \n",
"44 R Action 155 \n",
"45 R Action 137 \n",
".. ... ... ... \n",
"916 R Drama 109 \n",
"917 R Drama 104 \n",
"918 R Action 122 \n",
"920 R Crime 112 \n",
"922 PG-13 Drama 130 \n",
"923 PG-13 Drama 133 \n",
"924 PG-13 Crime 134 \n",
"925 R Drama 92 \n",
"926 R Drama 104 \n",
"927 R Crime 110 \n",
"931 R Crime 112 \n",
"939 R Drama 97 \n",
"941 PG Drama 175 \n",
"945 R Drama 120 \n",
"946 PG-13 Drama 107 \n",
"947 UNRATED Drama 89 \n",
"950 R Crime 108 \n",
"951 R Drama 105 \n",
"954 PG-13 Action 104 \n",
"955 R Drama 157 \n",
"958 PG-13 Drama 109 \n",
"963 R Action 118 \n",
"967 R Action 136 \n",
"968 R Drama 162 \n",
"969 R Crime 109 \n",
"970 R Drama 107 \n",
"972 NC-17 Drama 112 \n",
"973 PG-13 Drama 126 \n",
"976 PG-13 Action 138 \n",
"978 R Crime 126 \n",
"\n",
" actors_list \n",
"0 [u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt... \n",
"1 [u'Marlon Brando', u'Al Pacino', u'James Caan'] \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"3 [u'Christian Bale', u'Heath Ledger', u'Aaron E... \n",
"4 [u'John Travolta', u'Uma Thurman', u'Samuel L.... \n",
"5 [u'Henry Fonda', u'Lee J. Cobb', u'Martin Bals... \n",
"9 [u'Brad Pitt', u'Edward Norton', u'Helena Bonh... \n",
"11 [u'Leonardo DiCaprio', u'Joseph Gordon-Levitt'... \n",
"12 [u'Mark Hamill', u'Harrison Ford', u'Carrie Fi... \n",
"13 [u'Tom Hanks', u'Robin Wright', u'Gary Sinise'] \n",
"16 [u'Jack Nicholson', u'Louise Fletcher', u'Mich... \n",
"17 [u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K... \n",
"19 [u'Mark Hamill', u'Harrison Ford', u'Carrie Fi... \n",
"20 [u'Keanu Reeves', u'Laurence Fishburne', u'Car... \n",
"21 [u'Alexandre Rodrigues', u'Matheus Nachtergael... \n",
"22 [u'James Stewart', u'Donna Reed', u'Lionel Bar... \n",
"23 [u'Kevin Spacey', u'Gabriel Byrne', u'Chazz Pa... \n",
"24 [u'Morgan Freeman', u'Brad Pitt', u'Kevin Spac... \n",
"27 [u'Jodie Foster', u'Anthony Hopkins', u'Lawren... \n",
"28 [u'Jean Reno', u'Gary Oldman', u'Natalie Portm... \n",
"32 [u'Humphrey Bogart', u'Ingrid Bergman', u'Paul... \n",
"33 [u'Miles Teller', u'J.K. Simmons', u'Melissa B... \n",
"34 [u'Edward Norton', u'Edward Furlong', u\"Beverl... \n",
"36 [u'Tom Hanks', u'Matt Damon', u'Tom Sizemore'] \n",
"37 [u'Harrison Ford', u'Karen Allen', u'Paul Free... \n",
"40 [u'Tom Hanks', u'Michael Clarke Duncan', u'Dav... \n",
"41 [u'William Holden', u'Gloria Swanson', u'Erich... \n",
"43 [u'Christian Bale', u'Tom Hardy', u'Anne Hatha... \n",
"44 [u'Russell Crowe', u'Joaquin Phoenix', u'Conni... \n",
"45 [u'Arnold Schwarzenegger', u'Linda Hamilton', ... \n",
".. ... \n",
"916 [u'George Clooney', u'Vera Farmiga', u'Anna Ke... \n",
"917 [u'Keira Knightley', u'Mark Ruffalo', u'Adam L... \n",
"918 [u'Paul Walker', u'Cameron Bright', u'Chazz Pa... \n",
"920 [u'Harrison Ford', u'Kelly McGillis', u'Lukas ... \n",
"922 [u'Matthew McConaughey', u'Tye Sheridan', u'Ja... \n",
"923 [u'Evan Rachel Wood', u'Jim Sturgess', u'Joe A... \n",
"924 [u'Liam Neeson', u'Geoffrey Rush', u'Uma Thurm... \n",
"925 [u'Cate Blanchett', u'Judi Dench', u'Andrew Si... \n",
"926 [u'Oscar Isaac', u'Carey Mulligan', u'John Goo... \n",
"927 [u'Joseph Gordon-Levitt', u'Lukas Haas', u'Emi... \n",
"931 [u'Robert De Niro', u'Harvey Keitel', u'David ... \n",
"939 [u'Ethan Hawke', u'Sarah Snook', u'Noah Taylor'] \n",
"941 [u'Sean Connery', u\"Ryan O'Neal\", u'Michael Ca... \n",
"945 [u'Michael Shannon', u'Jessica Chastain', u'Sh... \n",
"946 [u'Julianne Moore', u'Dennis Quaid', u'Dennis ... \n",
"947 [u'Jack Nance', u'Charlotte Stewart', u'Allen ... \n",
"950 [u'Jennifer Tilly', u'Gina Gershon', u'Joe Pan... \n",
"951 [u'Johnny Depp', u'Christina Ricci', u'Miranda... \n",
"954 [u'Patrick Stewart', u'Hugh Jackman', u'Ian Mc... \n",
"955 [u'Jessica Chastain', u'Joel Edgerton', u'Chri... \n",
"958 [u'Cameron Diaz', u'Abigail Breslin', u'Alec B... \n",
"963 [u'Anne Parillaud', u'Marc Duret', u'Patrick F... \n",
"967 [u'Sean Connery', u'Nicolas Cage', u'Ed Harris'] \n",
"968 [u'Ralph Fiennes', u'Juliette Binoche', u'Will... \n",
"969 [u'Gerard Butler', u'Jamie Foxx', u'Leslie Bibb'] \n",
"970 [u'Michael Douglas', u'Tobey Maguire', u'Franc... \n",
"972 [u'Ryan Gosling', u'Michelle Williams', u'John... \n",
"973 [u'Tobey Maguire', u'Charlize Theron', u'Micha... \n",
"976 [u'Russell Crowe', u'Paul Bettany', u'Billy Bo... \n",
"978 [u'Charlie Sheen', u'Michael Douglas', u'Tamar... \n",
"\n",
"[538 rows x 6 columns]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies[movies.genre.isin(['Crime', 'Drama', 'Action'])]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"movies = pd.read_csv('http://bit.ly/imdbratings')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>9.3</td>\n",
" <td>The Shawshank Redemption</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>142</td>\n",
" <td>[u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>9.2</td>\n",
" <td>The Godfather</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>175</td>\n",
" <td>[u'Marlon Brando', u'Al Pacino', u'James Caan']</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>9.0</td>\n",
" <td>The Dark Knight</td>\n",
" <td>PG-13</td>\n",
" <td>Action</td>\n",
" <td>152</td>\n",
" <td>[u'Christian Bale', u'Heath Ledger', u'Aaron E...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8.9</td>\n",
" <td>Pulp Fiction</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>154</td>\n",
" <td>[u'John Travolta', u'Uma Thurman', u'Samuel L....</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" star_rating title content_rating genre duration \\\n",
"0 9.3 The Shawshank Redemption R Crime 142 \n",
"1 9.2 The Godfather R Crime 175 \n",
"2 9.1 The Godfather: Part II R Crime 200 \n",
"3 9.0 The Dark Knight PG-13 Action 152 \n",
"4 8.9 Pulp Fiction R Crime 154 \n",
"\n",
" actors_list \n",
"0 [u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt... \n",
"1 [u'Marlon Brando', u'Al Pacino', u'James Caan'] \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"3 [u'Christian Bale', u'Heath Ledger', u'Aaron E... \n",
"4 [u'John Travolta', u'Uma Thurman', u'Samuel L.... "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(979, 6)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies.shape"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"bools = []\n",
"for length in movies.duration:\n",
" bools.append(length >= 200) "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[False, False, True, False, False]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bools[0:5]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"is_long = pd.Series(bools)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 False\n",
"1 False\n",
"2 True\n",
"3 False\n",
"4 False\n",
"dtype: bool"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_long.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8.9</td>\n",
" <td>The Lord of the Rings: The Return of the King</td>\n",
" <td>PG-13</td>\n",
" <td>Adventure</td>\n",
" <td>201</td>\n",
" <td>[u'Elijah Wood', u'Viggo Mortensen', u'Ian McK...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>8.7</td>\n",
" <td>Seven Samurai</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>207</td>\n",
" <td>[u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>8.4</td>\n",
" <td>Once Upon a Time in America</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>229</td>\n",
" <td>[u'Robert De Niro', u'James Woods', u'Elizabet...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>8.4</td>\n",
" <td>Lawrence of Arabia</td>\n",
" <td>PG</td>\n",
" <td>Adventure</td>\n",
" <td>216</td>\n",
" <td>[u\"Peter O'Toole\", u'Alec Guinness', u'Anthony...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>142</th>\n",
" <td>8.3</td>\n",
" <td>Lagaan: Once Upon a Time in India</td>\n",
" <td>PG</td>\n",
" <td>Adventure</td>\n",
" <td>224</td>\n",
" <td>[u'Aamir Khan', u'Gracy Singh', u'Rachel Shell...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>157</th>\n",
" <td>8.2</td>\n",
" <td>Gone with the Wind</td>\n",
" <td>G</td>\n",
" <td>Drama</td>\n",
" <td>238</td>\n",
" <td>[u'Clark Gable', u'Vivien Leigh', u'Thomas Mit...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>8.1</td>\n",
" <td>Ben-Hur</td>\n",
" <td>G</td>\n",
" <td>Adventure</td>\n",
" <td>212</td>\n",
" <td>[u'Charlton Heston', u'Jack Hawkins', u'Stephe...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>445</th>\n",
" <td>7.9</td>\n",
" <td>The Ten Commandments</td>\n",
" <td>APPROVED</td>\n",
" <td>Adventure</td>\n",
" <td>220</td>\n",
" <td>[u'Charlton Heston', u'Yul Brynner', u'Anne Ba...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>476</th>\n",
" <td>7.8</td>\n",
" <td>Hamlet</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>242</td>\n",
" <td>[u'Kenneth Branagh', u'Julie Christie', u'Dere...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>630</th>\n",
" <td>7.7</td>\n",
" <td>Malcolm X</td>\n",
" <td>PG-13</td>\n",
" <td>Biography</td>\n",
" <td>202</td>\n",
" <td>[u'Denzel Washington', u'Angela Bassett', u'De...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>767</th>\n",
" <td>7.6</td>\n",
" <td>It's a Mad, Mad, Mad, Mad World</td>\n",
" <td>APPROVED</td>\n",
" <td>Action</td>\n",
" <td>205</td>\n",
" <td>[u'Spencer Tracy', u'Milton Berle', u'Ethel Me...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" star_rating title \\\n",
"2 9.1 The Godfather: Part II \n",
"7 8.9 The Lord of the Rings: The Return of the King \n",
"17 8.7 Seven Samurai \n",
"78 8.4 Once Upon a Time in America \n",
"85 8.4 Lawrence of Arabia \n",
"142 8.3 Lagaan: Once Upon a Time in India \n",
"157 8.2 Gone with the Wind \n",
"204 8.1 Ben-Hur \n",
"445 7.9 The Ten Commandments \n",
"476 7.8 Hamlet \n",
"630 7.7 Malcolm X \n",
"767 7.6 It's a Mad, Mad, Mad, Mad World \n",
"\n",
" content_rating genre duration \\\n",
"2 R Crime 200 \n",
"7 PG-13 Adventure 201 \n",
"17 UNRATED Drama 207 \n",
"78 R Crime 229 \n",
"85 PG Adventure 216 \n",
"142 PG Adventure 224 \n",
"157 G Drama 238 \n",
"204 G Adventure 212 \n",
"445 APPROVED Adventure 220 \n",
"476 PG-13 Drama 242 \n",
"630 PG-13 Biography 202 \n",
"767 APPROVED Action 205 \n",
"\n",
" actors_list \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"7 [u'Elijah Wood', u'Viggo Mortensen', u'Ian McK... \n",
"17 [u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K... \n",
"78 [u'Robert De Niro', u'James Woods', u'Elizabet... \n",
"85 [u\"Peter O'Toole\", u'Alec Guinness', u'Anthony... \n",
"142 [u'Aamir Khan', u'Gracy Singh', u'Rachel Shell... \n",
"157 [u'Clark Gable', u'Vivien Leigh', u'Thomas Mit... \n",
"204 [u'Charlton Heston', u'Jack Hawkins', u'Stephe... \n",
"445 [u'Charlton Heston', u'Yul Brynner', u'Anne Ba... \n",
"476 [u'Kenneth Branagh', u'Julie Christie', u'Dere... \n",
"630 [u'Denzel Washington', u'Angela Bassett', u'De... \n",
"767 [u'Spencer Tracy', u'Milton Berle', u'Ethel Me... "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies[is_long]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>star_rating</th>\n",
" <th>title</th>\n",
" <th>content_rating</th>\n",
" <th>genre</th>\n",
" <th>duration</th>\n",
" <th>actors_list</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9.1</td>\n",
" <td>The Godfather: Part II</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>200</td>\n",
" <td>[u'Al Pacino', u'Robert De Niro', u'Robert Duv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8.9</td>\n",
" <td>The Lord of the Rings: The Return of the King</td>\n",
" <td>PG-13</td>\n",
" <td>Adventure</td>\n",
" <td>201</td>\n",
" <td>[u'Elijah Wood', u'Viggo Mortensen', u'Ian McK...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>8.7</td>\n",
" <td>Seven Samurai</td>\n",
" <td>UNRATED</td>\n",
" <td>Drama</td>\n",
" <td>207</td>\n",
" <td>[u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>8.4</td>\n",
" <td>Once Upon a Time in America</td>\n",
" <td>R</td>\n",
" <td>Crime</td>\n",
" <td>229</td>\n",
" <td>[u'Robert De Niro', u'James Woods', u'Elizabet...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>8.4</td>\n",
" <td>Lawrence of Arabia</td>\n",
" <td>PG</td>\n",
" <td>Adventure</td>\n",
" <td>216</td>\n",
" <td>[u\"Peter O'Toole\", u'Alec Guinness', u'Anthony...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>142</th>\n",
" <td>8.3</td>\n",
" <td>Lagaan: Once Upon a Time in India</td>\n",
" <td>PG</td>\n",
" <td>Adventure</td>\n",
" <td>224</td>\n",
" <td>[u'Aamir Khan', u'Gracy Singh', u'Rachel Shell...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>157</th>\n",
" <td>8.2</td>\n",
" <td>Gone with the Wind</td>\n",
" <td>G</td>\n",
" <td>Drama</td>\n",
" <td>238</td>\n",
" <td>[u'Clark Gable', u'Vivien Leigh', u'Thomas Mit...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>8.1</td>\n",
" <td>Ben-Hur</td>\n",
" <td>G</td>\n",
" <td>Adventure</td>\n",
" <td>212</td>\n",
" <td>[u'Charlton Heston', u'Jack Hawkins', u'Stephe...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>445</th>\n",
" <td>7.9</td>\n",
" <td>The Ten Commandments</td>\n",
" <td>APPROVED</td>\n",
" <td>Adventure</td>\n",
" <td>220</td>\n",
" <td>[u'Charlton Heston', u'Yul Brynner', u'Anne Ba...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>476</th>\n",
" <td>7.8</td>\n",
" <td>Hamlet</td>\n",
" <td>PG-13</td>\n",
" <td>Drama</td>\n",
" <td>242</td>\n",
" <td>[u'Kenneth Branagh', u'Julie Christie', u'Dere...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>630</th>\n",
" <td>7.7</td>\n",
" <td>Malcolm X</td>\n",
" <td>PG-13</td>\n",
" <td>Biography</td>\n",
" <td>202</td>\n",
" <td>[u'Denzel Washington', u'Angela Bassett', u'De...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>767</th>\n",
" <td>7.6</td>\n",
" <td>It's a Mad, Mad, Mad, Mad World</td>\n",
" <td>APPROVED</td>\n",
" <td>Action</td>\n",
" <td>205</td>\n",
" <td>[u'Spencer Tracy', u'Milton Berle', u'Ethel Me...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" star_rating title \\\n",
"2 9.1 The Godfather: Part II \n",
"7 8.9 The Lord of the Rings: The Return of the King \n",
"17 8.7 Seven Samurai \n",
"78 8.4 Once Upon a Time in America \n",
"85 8.4 Lawrence of Arabia \n",
"142 8.3 Lagaan: Once Upon a Time in India \n",
"157 8.2 Gone with the Wind \n",
"204 8.1 Ben-Hur \n",
"445 7.9 The Ten Commandments \n",
"476 7.8 Hamlet \n",
"630 7.7 Malcolm X \n",
"767 7.6 It's a Mad, Mad, Mad, Mad World \n",
"\n",
" content_rating genre duration \\\n",
"2 R Crime 200 \n",
"7 PG-13 Adventure 201 \n",
"17 UNRATED Drama 207 \n",
"78 R Crime 229 \n",
"85 PG Adventure 216 \n",
"142 PG Adventure 224 \n",
"157 G Drama 238 \n",
"204 G Adventure 212 \n",
"445 APPROVED Adventure 220 \n",
"476 PG-13 Drama 242 \n",
"630 PG-13 Biography 202 \n",
"767 APPROVED Action 205 \n",
"\n",
" actors_list \n",
"2 [u'Al Pacino', u'Robert De Niro', u'Robert Duv... \n",
"7 [u'Elijah Wood', u'Viggo Mortensen', u'Ian McK... \n",
"17 [u'Toshir\\xf4 Mifune', u'Takashi Shimura', u'K... \n",
"78 [u'Robert De Niro', u'James Woods', u'Elizabet... \n",
"85 [u\"Peter O'Toole\", u'Alec Guinness', u'Anthony... \n",
"142 [u'Aamir Khan', u'Gracy Singh', u'Rachel Shell... \n",
"157 [u'Clark Gable', u'Vivien Leigh', u'Thomas Mit... \n",
"204 [u'Charlton Heston', u'Jack Hawkins', u'Stephe... \n",
"445 [u'Charlton Heston', u'Yul Brynner', u'Anne Ba... \n",
"476 [u'Kenneth Branagh', u'Julie Christie', u'Dere... \n",
"630 [u'Denzel Washington', u'Angela Bassett', u'De... \n",
"767 [u'Spencer Tracy', u'Milton Berle', u'Ethel Me... "
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movies[movies.duration >= 200]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
import pandas as pd
movies = pd.read_csv('http://bit.ly/imdbratings')
# FIRST WAY
booleans = []
for length in movies.duration:
if length >= 200:
booleans.append(True)
else:
booleans.append(False)
# OR
# > booleans.append(length >= 200)
is_long = pd.Series(booleans)
movies[is_long]
# SECOND WAY
movies[movies.duration >= 200]
# Filter using list in
movies[movies.genre.isin(['Crime', 'Action'])]
# Filter no null values
movies[movies.genre.notnull()]
以上是关于python Pandas - 过滤DataFrames和Series的主要内容,如果未能解决你的问题,请参考以下文章
Pandas文摘:Applying Operations Over pandas Dataframes