0% found this document useful (0 votes)
17 views38 pages

Session 17 Pandas Dataframes

The document shows how to create DataFrames from lists, dictionaries, and CSV files in Python using Pandas. It creates DataFrames from student data, movies data, and IPL matches data to demonstrate different data sources and structures that can be used with Pandas.

Uploaded by

Avantika Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views38 pages

Session 17 Pandas Dataframes

The document shows how to create DataFrames from lists, dictionaries, and CSV files in Python using Pandas. It creates DataFrames from student data, movies data, and IPL matches data to demonstrate different data sources and structures that can be used with Pandas.

Uploaded by

Avantika Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

import numpy as np

import pandas as pd

Creating DataFrame
# using lists
student_data = [
[100,80,10],
[90,70,7],
[120,100,14],
[80,50,2]
]

pd.DataFrame(student_data,columns=['iq','marks','package'])

iq marks package
0 100 80 10
1 90 70 7
2 120 100 14
3 80 50 2

# using dicts

student_dict = {
'name':['nitish','ankit','rupesh','rishabh','amit','ankita'],
'iq':[100,90,120,80,0,0],
'marks':[80,70,100,50,0,0],
'package':[10,7,14,2,0,0]
}

students = pd.DataFrame(student_dict)
students.set_index('name',inplace=True)
students

iq marks package
name
nitish 100 80 10
ankit 90 70 7
rupesh 120 100 14
rishabh 80 50 2
amit 0 0 0
ankita 0 0 0

# using read_csv
movies = pd.read_csv('movies.csv')
movies

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208
2 The Accidental Prime Minister (film) tt6986710
3 Why Cheat India tt8108208
4 Evening Shadows tt6028796
... ... ...
1624 Tera Mera Saath Rahen tt0301250
1625 Yeh Zindagi Ka Safar tt0298607
1626 Sabse Bada Sukh tt0069204
1627 Daaka tt10833860
1628 Humsafar tt2403201

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN
2 https://upload.wikimedia.org/wikipedia/en/thum...
3 https://upload.wikimedia.org/wikipedia/en/thum...
4 NaN
... ...
1624 https://upload.wikimedia.org/wikipedia/en/2/2b...
1625 https://upload.wikimedia.org/wikipedia/en/thum...
1626 NaN
1627 https://upload.wikimedia.org/wikipedia/en/thum...
1628 https://upload.wikimedia.org/wikipedia/en/thum...

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
1 https://en.wikipedia.org/wiki/Battalion_609
2 https://en.wikipedia.org/wiki/The_Accidental_P...
3 https://en.wikipedia.org/wiki/Why_Cheat_India
4 https://en.wikipedia.org/wiki/Evening_Shadows
... ...
1624 https://en.wikipedia.org/wiki/Tera_Mera_Saath_...
1625 https://en.wikipedia.org/wiki/Yeh_Zindagi_Ka_S...
1626 https://en.wikipedia.org/wiki/Sabse_Bada_Sukh
1627 https://en.wikipedia.org/wiki/Daaka
1628 https://en.wikipedia.org/wiki/Humsafar

title_y original_title
is_adult \
0 Uri: The Surgical Strike Uri: The Surgical Strike
0
1 Battalion 609 Battalion 609
0
2 The Accidental Prime Minister The Accidental Prime Minister
0
3 Why Cheat India Why Cheat India
0
4 Evening Shadows Evening Shadows
0
... ... ...
...
1624 Tera Mera Saath Rahen Tera Mera Saath Rahen
0
1625 Yeh Zindagi Ka Safar Yeh Zindagi Ka Safar
0
1626 Sabse Bada Sukh Sabse Bada Sukh
0
1627 Daaka Daaka
0
1628 Humsafar Humsafar
0

year_of_release runtime genres imdb_rating


imdb_votes \
0 2019 138 Action|Drama|War 8.4
35112
1 2019 131 War 4.1
73
2 2019 112 Biography|Drama 6.1
5549
3 2019 121 Crime|Drama 6.0
1891
4 2018 102 Drama 7.3
280
... ... ... ... ... .
..
1624 2001 148 Drama 4.9
278
1625 2001 146 Drama 3.0
133
1626 2018 \N Comedy|Drama 6.1
13
1627 2019 136 Action 7.4
38
1628 2011 35 Drama|Romance 9.0
2968

story \
0 Divided over five chapters the film chronicle...
1 The story revolves around a cricket match betw...
2 Based on the memoir by Indian policy analyst S...
3 The movie focuses on existing malpractices in ...
4 While gay rights and marriage equality has bee...
... ...
1624 Raj Dixit lives with his younger brother Rahu...
1625 Hindi pop-star Sarina Devan lives a wealthy ...
1626 Village born Lalloo re-locates to Bombay and ...
1627 Shinda tries robbing a bank so he can be wealt...
1628 Sara and Ashar are childhood friends who share...

summary tagline \
0 Indian army special forces execute a covert op... NaN
1 The story of Battalion 609 revolves around a c... NaN
2 Explores Manmohan Singh's tenure as the Prime ... NaN
3 The movie focuses on existing malpractices in ... NaN
4 Under the 'Evening Shadows' truth often plays... NaN
... ... ...
1624 A man is torn between his handicapped brother ... NaN
1625 A singer finds out she was adopted when the ed... NaN
1626 Village born Lalloo re-locates to Bombay and ... NaN
1627 Shinda tries robbing a bank so he can be wealt... NaN
1628 Ashar and Khirad are forced to get married due... NaN

actors \
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga...
1 Vicky Ahuja|Shoaib Ibrahim|Shrikant Kamat|Elen...
2 Anupam Kher|Akshaye Khanna|Aahana Kumra|Atul S...
3 Emraan Hashmi|Shreya Dhanwanthary|Snighdadeep ...
4 Mona Ambegaonkar|Ananth Narayan Mahadevan|Deva...
... ...
1624 Ajay Devgn|Sonali Bendre|Namrata Shirodkar|Pre...
1625 Ameesha Patel|Jimmy Sheirgill|Nafisa Ali|Gulsh...
1626 Vijay Arora|Asrani|Rajni Bala|Kumud Damle|Utpa...
1627 Gippy Grewal|Zareen Khan|
1628 Fawad Khan|

wins_nominations release_date
0 4 wins 11 January 2019 (USA)
1 NaN 11 January 2019 (India)
2 NaN 11 January 2019 (USA)
3 NaN 18 January 2019 (USA)
4 17 wins & 1 nomination 11 January 2019 (India)
... ... ...
1624 NaN 7 November 2001 (India)
1625 NaN 16 November 2001 (India)
1626 NaN NaN
1627 NaN 1 November 2019 (USA)
1628 NaN TV Series (2011–2012)

[1629 rows x 18 columns]

ipl = pd.read_csv('ipl-matches.csv')
ipl

ID City Date Season MatchNumber \


0 1312200 Ahmedabad 2022-05-29 2022 Final
1 1312199 Ahmedabad 2022-05-27 2022 Qualifier 2
2 1312198 Kolkata 2022-05-25 2022 Eliminator
3 1312197 Kolkata 2022-05-24 2022 Qualifier 1
4 1304116 Mumbai 2022-05-22 2022 70
.. ... ... ... ... ...
945 335986 Kolkata 2008-04-20 2007/08 4
946 335985 Mumbai 2008-04-20 2007/08 5
947 335984 Delhi 2008-04-19 2007/08 3
948 335983 Chandigarh 2008-04-19 2007/08 2
949 335982 Bangalore 2008-04-18 2007/08 1

Team1 Team2 \
0 Rajasthan Royals Gujarat Titans
1 Royal Challengers Bangalore Rajasthan Royals
2 Royal Challengers Bangalore Lucknow Super Giants
3 Rajasthan Royals Gujarat Titans
4 Sunrisers Hyderabad Punjab Kings
.. ... ...
945 Kolkata Knight Riders Deccan Chargers
946 Mumbai Indians Royal Challengers Bangalore
947 Delhi Daredevils Rajasthan Royals
948 Kings XI Punjab Chennai Super Kings
949 Royal Challengers Bangalore Kolkata Knight Riders

Venue
TossWinner \
0 Narendra Modi Stadium, Ahmedabad Rajasthan
Royals
1 Narendra Modi Stadium, Ahmedabad Rajasthan
Royals
2 Eden Gardens, Kolkata Lucknow Super
Giants
3 Eden Gardens, Kolkata Gujarat
Titans
4 Wankhede Stadium, Mumbai Sunrisers
Hyderabad
.. ...
...
945 Eden Gardens Deccan
Chargers
946 Wankhede Stadium Mumbai
Indians
947 Feroz Shah Kotla Rajasthan
Royals
948 Punjab Cricket Association Stadium, Mohali Chennai Super
Kings
949 M Chinnaswamy Stadium Royal Challengers
Bangalore

TossDecision SuperOver WinningTeam WonBy


Margin \
0 bat N Gujarat Titans Wickets
7.0
1 field N Rajasthan Royals Wickets
7.0
2 field N Royal Challengers Bangalore Runs
14.0
3 field N Gujarat Titans Wickets
7.0
4 bat N Punjab Kings Wickets
5.0
.. ... ... ... ... .
..
945 bat N Kolkata Knight Riders Wickets
5.0
946 bat N Royal Challengers Bangalore Wickets
5.0
947 bat N Delhi Daredevils Wickets
9.0
948 bat N Chennai Super Kings Runs
33.0
949 field N Kolkata Knight Riders Runs
140.0

method Player_of_Match
Team1Players \
0 NaN HH Pandya ['YBK Jaiswal', 'JC Buttler', 'SV Samson',
'D ...
1 NaN JC Buttler ['V Kohli', 'F du Plessis', 'RM Patidar',
'GJ ...
2 NaN RM Patidar ['V Kohli', 'F du Plessis', 'RM Patidar',
'GJ ...
3 NaN DA Miller ['YBK Jaiswal', 'JC Buttler', 'SV Samson',
'D ...
4 NaN Harpreet Brar ['PK Garg', 'Abhishek Sharma', 'RA
Tripathi', ...
.. ... ...
...
945 NaN DJ Hussey ['WP Saha', 'BB McCullum', 'RT Ponting',
'SC G...
946 NaN MV Boucher ['L Ronchi', 'ST Jayasuriya', 'DJ
Thornely', '...
947 NaN MF Maharoof ['G Gambhir', 'V Sehwag', 'S Dhawan', 'MK
Tiwa...
948 NaN MEK Hussey ['K Goel', 'JR Hopes', 'KC Sangakkara',
'Yuvra...
949 NaN BB McCullum ['R Dravid', 'W Jaffer', 'V Kohli', 'JH
Kallis...

Team2Players Umpire1
\
0 ['WP Saha', 'Shubman Gill', 'MS Wade', 'HH Pan... CB Gaffaney

1 ['YBK Jaiswal', 'JC Buttler', 'SV Samson', 'D ... CB Gaffaney

2 ['Q de Kock', 'KL Rahul', 'M Vohra', 'DJ Hooda... J Madanagopal


3 ['WP Saha', 'Shubman Gill', 'MS Wade', 'HH Pan... BNJ Oxenford

4 ['JM Bairstow', 'S Dhawan', 'M Shahrukh Khan',... AK Chaudhary

.. ... ...

945 ['AC Gilchrist', 'Y Venugopal Rao', 'VVS Laxma... BF Bowden

946 ['S Chanderpaul', 'R Dravid', 'LRPL Taylor', '... SJ Davis

947 ['T Kohli', 'YK Pathan', 'SR Watson', 'M Kaif'... Aleem Dar

948 ['PA Patel', 'ML Hayden', 'MEK Hussey', 'MS Dh... MR Benson

949 ['SC Ganguly', 'BB McCullum', 'RT Ponting', 'D... Asad Rauf

Umpire2
0 Nitin Menon
1 Nitin Menon
2 MA Gough
3 VK Sharma
4 NA Patwardhan
.. ...
945 K Hariharan
946 DJ Harper
947 GA Pratapkumar
948 SL Shastri
949 RE Koertzen

[950 rows x 20 columns]

DataFrame Attributes and Methods


# shape
movies.shape
ipl.shape

(950, 20)

# dtypes
movies.dtypes
ipl.dtypes

ID int64
City object
Date object
Season object
MatchNumber object
Team1 object
Team2 object
Venue object
TossWinner object
TossDecision object
SuperOver object
WinningTeam object
WonBy object
Margin float64
method object
Player_of_Match object
Team1Players object
Team2Players object
Umpire1 object
Umpire2 object
dtype: object

# index
movies.index
ipl.index

RangeIndex(start=0, stop=950, step=1)

# columns
movies.columns
ipl.columns
student.columns

Index(['iq', 'marks', 'package'], dtype='object')

# values
student.values
ipl.values

array([[1312200, 'Ahmedabad', '2022-05-29', ...,


"['WP Saha', 'Shubman Gill', 'MS Wade', 'HH Pandya', 'DA
Miller', 'R Tewatia', 'Rashid Khan', 'R Sai Kishore', 'LH Ferguson',
'Yash Dayal', 'Mohammed Shami']",
'CB Gaffaney', 'Nitin Menon'],
[1312199, 'Ahmedabad', '2022-05-27', ...,
"['YBK Jaiswal', 'JC Buttler', 'SV Samson', 'D Padikkal', 'SO
Hetmyer', 'R Parag', 'R Ashwin', 'TA Boult', 'YS Chahal', 'M Prasidh
Krishna', 'OC McCoy']",
'CB Gaffaney', 'Nitin Menon'],
[1312198, 'Kolkata', '2022-05-25', ...,
"['Q de Kock', 'KL Rahul', 'M Vohra', 'DJ Hooda', 'MP
Stoinis', 'E Lewis', 'KH Pandya', 'PVD Chameera', 'Mohsin Khan',
'Avesh Khan', 'Ravi Bishnoi']",
'J Madanagopal', 'MA Gough'],
...,
[335984, 'Delhi', '2008-04-19', ...,
"['T Kohli', 'YK Pathan', 'SR Watson', 'M Kaif', 'DS Lehmann',
'RA Jadeja', 'M Rawat', 'D Salunkhe', 'SK Warne', 'SK Trivedi', 'MM
Patel']",
'Aleem Dar', 'GA Pratapkumar'],
[335983, 'Chandigarh', '2008-04-19', ...,
"['PA Patel', 'ML Hayden', 'MEK Hussey', 'MS Dhoni', 'SK
Raina', 'JDP Oram', 'S Badrinath', 'Joginder Sharma', 'P Amarnath',
'MS Gony', 'M Muralitharan']",
'MR Benson', 'SL Shastri'],
[335982, 'Bangalore', '2008-04-18', ...,
"['SC Ganguly', 'BB McCullum', 'RT Ponting', 'DJ Hussey',
'Mohammad Hafeez', 'LR Shukla', 'WP Saha', 'AB Agarkar', 'AB Dinda',
'M Kartik', 'I Sharma']",
'Asad Rauf', 'RE Koertzen']], dtype=object)

# head and tail


movies.head(2)

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
1 https://en.wikipedia.org/wiki/Battalion_609

title_y original_title is_adult \


0 Uri: The Surgical Strike Uri: The Surgical Strike 0
1 Battalion 609 Battalion 609 0

year_of_release runtime genres imdb_rating imdb_votes


\
0 2019 138 Action|Drama|War 8.4 35112

1 2019 131 War 4.1 73

story \
0 Divided over five chapters the film chronicle...
1 The story revolves around a cricket match betw...

summary tagline \
0 Indian army special forces execute a covert op... NaN
1 The story of Battalion 609 revolves around a c... NaN

actors wins_nominations
\
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga... 4 wins
1 Vicky Ahuja|Shoaib Ibrahim|Shrikant Kamat|Elen... NaN

release_date
0 11 January 2019 (USA)
1 11 January 2019 (India)

ipl.tail(2)

ID City Date Season MatchNumber \


948 335983 Chandigarh 2008-04-19 2007/08 2
949 335982 Bangalore 2008-04-18 2007/08 1

Team1 Team2 \
948 Kings XI Punjab Chennai Super Kings
949 Royal Challengers Bangalore Kolkata Knight Riders

Venue
TossWinner \
948 Punjab Cricket Association Stadium, Mohali Chennai Super
Kings
949 M Chinnaswamy Stadium Royal Challengers
Bangalore

TossDecision SuperOver WinningTeam WonBy Margin method


\
948 bat N Chennai Super Kings Runs 33.0 NaN

949 field N Kolkata Knight Riders Runs 140.0 NaN

Player_of_Match Team1Players
\
948 MEK Hussey ['K Goel', 'JR Hopes', 'KC Sangakkara', 'Yuvra...

949 BB McCullum ['R Dravid', 'W Jaffer', 'V Kohli', 'JH Kallis...

Team2Players Umpire1
Umpire2
948 ['PA Patel', 'ML Hayden', 'MEK Hussey', 'MS Dh... MR Benson SL
Shastri
949 ['SC Ganguly', 'BB McCullum', 'RT Ponting', 'D... Asad Rauf RE
Koertzen

# sample
ipl.sample(5)

ID City Date Season MatchNumber \


336 1082628 Mumbai 2017-05-01 2017 38
98 1254107 Sharjah 2021-09-25 2021 37
890 392182 Cape Town 2009-04-18 2009 2
157 1216533 Abu Dhabi 2020-10-19 2020/21 37
386 980991 Chandigarh 2016-05-15 2016 46

Team1 Team2 \
336 Mumbai Indians Royal Challengers Bangalore
98 Punjab Kings Sunrisers Hyderabad
890 Royal Challengers Bangalore Rajasthan Royals
157 Chennai Super Kings Rajasthan Royals
386 Kings XI Punjab Sunrisers Hyderabad

Venue \
336 Wankhede Stadium
98 Sharjah Cricket Stadium
890 Newlands
157 Sheikh Zayed Stadium
386 Punjab Cricket Association IS Bindra Stadium, ...

TossWinner TossDecision SuperOver \


336 Royal Challengers Bangalore bat N
98 Sunrisers Hyderabad field N
890 Royal Challengers Bangalore bat N
157 Chennai Super Kings bat N
386 Kings XI Punjab bat N

WinningTeam WonBy Margin method


Player_of_Match \
336 Mumbai Indians Wickets 5.0 NaN RG
Sharma
98 Punjab Kings Runs 5.0 NaN JO
Holder
890 Royal Challengers Bangalore Runs 75.0 NaN R
Dravid
157 Rajasthan Royals Wickets 7.0 NaN JC
Buttler
386 Sunrisers Hyderabad Wickets 7.0 NaN HM
Amla

Team1Players \
336 ['PA Patel', 'JC Buttler', 'N Rana', 'RG Sharm...
98 ['KL Rahul', 'MA Agarwal', 'CH Gayle', 'AK Mar...
890 ['JD Ryder', 'RV Uthappa', 'LRPL Taylor', 'KP ...
157 ['SM Curran', 'F du Plessis', 'SR Watson', 'AT...
386 ['HM Amla', 'M Vijay', 'WP Saha', 'Gurkeerat S...

Team2Players
Umpire1 \
336 ['V Kohli', 'Mandeep Singh', 'TM Head', 'AB de... AK
Chaudhary
98 ['DA Warner', 'WP Saha', 'KS Williamson', 'MK ... RK
Illingworth
890 ['GC Smith', 'SA Asnodkar', 'NK Patel', 'T Hen... BR
Doctrove
157 ['BA Stokes', 'RV Uthappa', 'SV Samson', 'SPD ... CB
Gaffaney
386 ['DA Warner', 'S Dhawan', 'DJ Hooda', 'Yuvraj ... KN
Ananthapadmanabhan

Umpire2
336 CB Gaffaney
98 YC Barde
890 RB Tiffin
157 VK Sharma
386 M Erasmus

# info
movies.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1629 entries, 0 to 1628
Data columns (total 18 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 title_x 1629 non-null object
1 imdb_id 1629 non-null object
2 poster_path 1526 non-null object
3 wiki_link 1629 non-null object
4 title_y 1629 non-null object
5 original_title 1629 non-null object
6 is_adult 1629 non-null int64
7 year_of_release 1629 non-null int64
8 runtime 1629 non-null object
9 genres 1629 non-null object
10 imdb_rating 1629 non-null float64
11 imdb_votes 1629 non-null int64
12 story 1609 non-null object
13 summary 1629 non-null object
14 tagline 557 non-null object
15 actors 1624 non-null object
16 wins_nominations 707 non-null object
17 release_date 1522 non-null object
dtypes: float64(1), int64(3), object(14)
memory usage: 229.2+ KB

ipl.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 950 entries, 0 to 949
Data columns (total 20 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 950 non-null int64
1 City 899 non-null object
2 Date 950 non-null object
3 Season 950 non-null object
4 MatchNumber 950 non-null object
5 Team1 950 non-null object
6 Team2 950 non-null object
7 Venue 950 non-null object
8 TossWinner 950 non-null object
9 TossDecision 950 non-null object
10 SuperOver 946 non-null object
11 WinningTeam 946 non-null object
12 WonBy 950 non-null object
13 Margin 932 non-null float64
14 method 19 non-null object
15 Player_of_Match 946 non-null object
16 Team1Players 950 non-null object
17 Team2Players 950 non-null object
18 Umpire1 950 non-null object
19 Umpire2 950 non-null object
dtypes: float64(1), int64(1), object(18)
memory usage: 148.6+ KB

# describe
movies.describe()

is_adult year_of_release imdb_rating imdb_votes


count 1629.0 1629.000000 1629.000000 1629.000000
mean 0.0 2010.263966 5.557459 5384.263352
std 0.0 5.381542 1.567609 14552.103231
min 0.0 2001.000000 0.000000 0.000000
25% 0.0 2005.000000 4.400000 233.000000
50% 0.0 2011.000000 5.600000 1000.000000
75% 0.0 2015.000000 6.800000 4287.000000
max 0.0 2019.000000 9.400000 310481.000000

ipl.describe()

ID Margin
count 9.500000e+02 932.000000
mean 8.304852e+05 17.056867
std 3.375678e+05 21.633109
min 3.359820e+05 1.000000
25% 5.012612e+05 6.000000
50% 8.297380e+05 8.000000
75% 1.175372e+06 19.000000
max 1.312200e+06 146.000000
# isnull
movies.isnull().sum()

title_x 0
imdb_id 0
poster_path 103
wiki_link 0
title_y 0
original_title 0
is_adult 0
year_of_release 0
runtime 0
genres 0
imdb_rating 0
imdb_votes 0
story 20
summary 0
tagline 1072
actors 5
wins_nominations 922
release_date 107
dtype: int64

# duplicated
movies.duplicated().sum()

students.duplicated().sum()

# rename
students

iq percent lpa
0 100 80 10
1 90 70 7
2 120 100 14
3 80 50 2
4 0 0 0
5 0 0 0

students.rename(columns={'marks':'percent','package':'lpa'},inplace=Tr
ue)

Math Methods
# sum -> axis argument
students.sum(axis=0)
iq 390
percent 300
lpa 33
dtype: int64

students.mean(axis=1)

0 63.333333
1 55.666667
2 78.000000
3 44.000000
4 0.000000
5 0.000000
dtype: float64

students.var()

iq 2710.0
percent 1760.0
lpa 33.5
dtype: float64

Selecting cols from a DataFrame


# single cols
movies['title_x']

0 Uri: The Surgical Strike


1 Battalion 609
2 The Accidental Prime Minister (film)
3 Why Cheat India
4 Evening Shadows
...
1624 Tera Mera Saath Rahen
1625 Yeh Zindagi Ka Safar
1626 Sabse Bada Sukh
1627 Daaka
1628 Humsafar
Name: title_x, Length: 1629, dtype: object

ipl['Venue']

0 Narendra Modi Stadium, Ahmedabad


1 Narendra Modi Stadium, Ahmedabad
2 Eden Gardens, Kolkata
3 Eden Gardens, Kolkata
4 Wankhede Stadium, Mumbai
...
945 Eden Gardens
946 Wankhede Stadium
947 Feroz Shah Kotla
948 Punjab Cricket Association Stadium, Mohali
949 M Chinnaswamy Stadium
Name: Venue, Length: 950, dtype: object

# multiple cols
movies[['year_of_release','actors','title_x']]

year_of_release
actors \
0 2019 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami
Ga...
1 2019 Vicky Ahuja|Shoaib Ibrahim|Shrikant Kamat|
Elen...
2 2019 Anupam Kher|Akshaye Khanna|Aahana Kumra|Atul
S...
3 2019 Emraan Hashmi|Shreya Dhanwanthary|
Snighdadeep ...
4 2018 Mona Ambegaonkar|Ananth Narayan Mahadevan|
Deva...
... ... .
..
1624 2001 Ajay Devgn|Sonali Bendre|Namrata Shirodkar|
Pre...
1625 2001 Ameesha Patel|Jimmy Sheirgill|Nafisa Ali|
Gulsh...
1626 2018 Vijay Arora|Asrani|Rajni Bala|Kumud Damle|
Utpa...
1627 2019 Gippy Grewal|Zareen
Khan|
1628 2011 Fawad
Khan|

title_x
0 Uri: The Surgical Strike
1 Battalion 609
2 The Accidental Prime Minister (film)
3 Why Cheat India
4 Evening Shadows
... ...
1624 Tera Mera Saath Rahen
1625 Yeh Zindagi Ka Safar
1626 Sabse Bada Sukh
1627 Daaka
1628 Humsafar

[1629 rows x 3 columns]

ipl[['Team1','Team2','WinningTeam']]
Team1 Team2 \
0 Rajasthan Royals Gujarat Titans
1 Royal Challengers Bangalore Rajasthan Royals
2 Royal Challengers Bangalore Lucknow Super Giants
3 Rajasthan Royals Gujarat Titans
4 Sunrisers Hyderabad Punjab Kings
.. ... ...
945 Kolkata Knight Riders Deccan Chargers
946 Mumbai Indians Royal Challengers Bangalore
947 Delhi Daredevils Rajasthan Royals
948 Kings XI Punjab Chennai Super Kings
949 Royal Challengers Bangalore Kolkata Knight Riders

WinningTeam
0 Gujarat Titans
1 Rajasthan Royals
2 Royal Challengers Bangalore
3 Gujarat Titans
4 Punjab Kings
.. ...
945 Kolkata Knight Riders
946 Royal Challengers Bangalore
947 Delhi Daredevils
948 Chennai Super Kings
949 Kolkata Knight Riders

[950 rows x 3 columns]

Selecting rows from a DataFrame


• iloc - searches using index positions
• loc - searches using index labels
# single row
movies.iloc[5]

title_x Soni (film)


imdb_id tt6078866
poster_path https://upload.wikimedia.org/wikipedia/en/thum...
wiki_link https://en.wikipedia.org/wiki/Soni_(film)
title_y Soni
original_title Soni
is_adult 0
year_of_release 2018
runtime 97
genres Drama
imdb_rating 7.2
imdb_votes 1595
story Soni a young policewoman in Delhi and her su...
summary While fighting crimes against women in Delhi ...
tagline NaN
actors Geetika Vidya Ohlyan|Saloni Batra|Vikas Shukla...
wins_nominations 3 wins & 5 nominations
release_date 18 January 2019 (USA)
Name: 5, dtype: object

# multiple row
movies.iloc[:5]

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208
2 The Accidental Prime Minister (film) tt6986710
3 Why Cheat India tt8108208
4 Evening Shadows tt6028796

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN
2 https://upload.wikimedia.org/wikipedia/en/thum...
3 https://upload.wikimedia.org/wikipedia/en/thum...
4 NaN

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
1 https://en.wikipedia.org/wiki/Battalion_609
2 https://en.wikipedia.org/wiki/The_Accidental_P...
3 https://en.wikipedia.org/wiki/Why_Cheat_India
4 https://en.wikipedia.org/wiki/Evening_Shadows

title_y original_title
is_adult \
0 Uri: The Surgical Strike Uri: The Surgical Strike
0
1 Battalion 609 Battalion 609
0
2 The Accidental Prime Minister The Accidental Prime Minister
0
3 Why Cheat India Why Cheat India
0
4 Evening Shadows Evening Shadows
0

year_of_release runtime genres imdb_rating imdb_votes


\
0 2019 138 Action|Drama|War 8.4 35112

1 2019 131 War 4.1 73

2 2019 112 Biography|Drama 6.1 5549


3 2019 121 Crime|Drama 6.0 1891

4 2018 102 Drama 7.3 280

story \
0 Divided over five chapters the film chronicle...
1 The story revolves around a cricket match betw...
2 Based on the memoir by Indian policy analyst S...
3 The movie focuses on existing malpractices in ...
4 While gay rights and marriage equality has bee...

summary tagline \
0 Indian army special forces execute a covert op... NaN
1 The story of Battalion 609 revolves around a c... NaN
2 Explores Manmohan Singh's tenure as the Prime ... NaN
3 The movie focuses on existing malpractices in ... NaN
4 Under the 'Evening Shadows' truth often plays... NaN

actors
wins_nominations \
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga...
4 wins
1 Vicky Ahuja|Shoaib Ibrahim|Shrikant Kamat|Elen...
NaN
2 Anupam Kher|Akshaye Khanna|Aahana Kumra|Atul S...
NaN
3 Emraan Hashmi|Shreya Dhanwanthary|Snighdadeep ...
NaN
4 Mona Ambegaonkar|Ananth Narayan Mahadevan|Deva... 17 wins & 1
nomination

release_date
0 11 January 2019 (USA)
1 11 January 2019 (India)
2 11 January 2019 (USA)
3 18 January 2019 (USA)
4 11 January 2019 (India)

# fancy indexing
movies.iloc[[0,4,5]]

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
4 Evening Shadows tt6028796
5 Soni (film) tt6078866

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
4 NaN
5 https://upload.wikimedia.org/wikipedia/en/thum...

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
4 https://en.wikipedia.org/wiki/Evening_Shadows
5 https://en.wikipedia.org/wiki/Soni_(film)

title_y original_title is_adult \


0 Uri: The Surgical Strike Uri: The Surgical Strike 0
4 Evening Shadows Evening Shadows 0
5 Soni Soni 0

year_of_release runtime genres imdb_rating imdb_votes


\
0 2019 138 Action|Drama|War 8.4 35112

4 2018 102 Drama 7.3 280

5 2018 97 Drama 7.2 1595

story \
0 Divided over five chapters the film chronicle...
4 While gay rights and marriage equality has bee...
5 Soni a young policewoman in Delhi and her su...

summary tagline \
0 Indian army special forces execute a covert op... NaN
4 Under the 'Evening Shadows' truth often plays... NaN
5 While fighting crimes against women in Delhi ... NaN

actors
wins_nominations \
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga...
4 wins
4 Mona Ambegaonkar|Ananth Narayan Mahadevan|Deva... 17 wins & 1
nomination
5 Geetika Vidya Ohlyan|Saloni Batra|Vikas Shukla... 3 wins & 5
nominations

release_date
0 11 January 2019 (USA)
4 11 January 2019 (India)
5 18 January 2019 (USA)

# loc
students

iq marks package
name
nitish 100 80 10
ankit 90 70 7
rupesh 120 100 14
rishabh 80 50 2
amit 0 0 0
ankita 0 0 0

students.loc['nitish']

iq 100
marks 80
package 10
Name: nitish, dtype: int64

students.loc['nitish':'rishabh':2]

iq marks package
name
nitish 100 80 10
rupesh 120 100 14

students.loc[['nitish','ankita','rupesh']]

iq marks package
name
nitish 100 80 10
ankita 0 0 0
rupesh 120 100 14

students.iloc[[0,3,4]]

iq marks package
name
nitish 100 80 10
rishabh 80 50 2
amit 0 0 0

Selecting both rows and cols


movies.iloc[0:3,0:3]

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208
2 The Accidental Prime Minister (film) tt6986710

poster_path
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN
2 https://upload.wikimedia.org/wikipedia/en/thum...

movies.loc[0:2,'title_x':'poster_path']
title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208
2 The Accidental Prime Minister (film) tt6986710

poster_path
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN
2 https://upload.wikimedia.org/wikipedia/en/thum...

Filtering a DataFrame
ipl.head(2)

ID City Date Season MatchNumber \


0 1312200 Ahmedabad 2022-05-29 2022 Final
1 1312199 Ahmedabad 2022-05-27 2022 Qualifier 2

Team1 Team2 \
0 Rajasthan Royals Gujarat Titans
1 Royal Challengers Bangalore Rajasthan Royals

Venue TossWinner TossDecision


SuperOver \
0 Narendra Modi Stadium, Ahmedabad Rajasthan Royals bat
N
1 Narendra Modi Stadium, Ahmedabad Rajasthan Royals field
N

WinningTeam WonBy Margin method Player_of_Match \


0 Gujarat Titans Wickets 7.0 NaN HH Pandya
1 Rajasthan Royals Wickets 7.0 NaN JC Buttler

Team1Players \
0 ['YBK Jaiswal', 'JC Buttler', 'SV Samson', 'D ...
1 ['V Kohli', 'F du Plessis', 'RM Patidar', 'GJ ...

Team2Players Umpire1
Umpire2
0 ['WP Saha', 'Shubman Gill', 'MS Wade', 'HH Pan... CB Gaffaney
Nitin Menon
1 ['YBK Jaiswal', 'JC Buttler', 'SV Samson', 'D ... CB Gaffaney
Nitin Menon

# find all the final winners


mask = ipl['MatchNumber'] == 'Final'
new_df = ipl[mask]
new_df[['Season','WinningTeam']]

ipl[ipl['MatchNumber'] == 'Final'][['Season','WinningTeam']]
Season WinningTeam
0 2022 Gujarat Titans
74 2021 Chennai Super Kings
134 2020/21 Mumbai Indians
194 2019 Mumbai Indians
254 2018 Chennai Super Kings
314 2017 Mumbai Indians
373 2016 Sunrisers Hyderabad
433 2015 Mumbai Indians
492 2014 Kolkata Knight Riders
552 2013 Mumbai Indians
628 2012 Kolkata Knight Riders
702 2011 Chennai Super Kings
775 2009/10 Chennai Super Kings
835 2009 Deccan Chargers
892 2007/08 Rajasthan Royals

# how many super over finishes have occured


ipl[ipl['SuperOver'] == 'Y'].shape[0]

14

# how many matches has csk won in kolkata


ipl[(ipl['City'] == 'Kolkata') & (ipl['WinningTeam'] == 'Chennai Super
Kings')].shape[0]

# toss winner is match winner in percentage


(ipl[ipl['TossWinner'] ==
ipl['WinningTeam']].shape[0]/ipl.shape[0])*100

51.473684210526315

# movies with rating higher than 8 and votes>10000


movies[(movies['imdb_rating'] > 8.5) & (movies['imdb_votes'] >
10000)].shape[0]

# Action movies with rating higher than 7.5


# mask1 = movies['genres'].str.split('|').apply(lambda x:'Action' in
x)
mask1 = movies['genres'].str.contains('Action')
mask2 = movies['imdb_rating'] > 7.5

movies[mask1 & mask2]

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
41 Family of Thakurganj tt8897986
84 Mukkabaaz tt7180544
106 Raazi tt7098658
110 Parmanu: The Story of Pokhran tt6826438
112 Bhavesh Joshi Superhero tt6129302
169 The Ghazi Attack tt6299040
219 Raag Desh (film) tt6080746
258 Irudhi Suttru tt5310090
280 Laal Rang tt5600714
297 Udta Punjab tt4434004
354 Dangal (film) tt5074352
362 Bajrangi Bhaijaan tt3863552
365 Baby (2015 Hindi film) tt3848892
393 Detective Byomkesh Bakshy! tt3447364
449 Titli (2014 film) tt3019620
536 Haider (film) tt3390572
589 Vishwaroopam tt2199711
625 Madras Cafe tt2855648
668 Paan Singh Tomar (film) tt1620933
693 Gangs of Wasseypur tt1954470
694 Gangs of Wasseypur – Part 2 tt1954470
982 Jodhaa Akbar tt0449994
1039 1971 (2007 film) tt0983990
1058 Black Friday (2007 film) tt0400234
1188 Omkara (2006 film) tt0488414
1293 Sarkar (2005 film) tt0432047
1294 Sehar tt0477857
1361 Lakshya (film) tt0323013
1432 Gangaajal tt0373856
1495 Company (film) tt0296574
1554 The Legend of Bhagat Singh tt0319736
1607 Nayak (2001 Hindi film) tt0291376

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
41 https://upload.wikimedia.org/wikipedia/en/9/99...
84 https://upload.wikimedia.org/wikipedia/en/thum...
106 https://upload.wikimedia.org/wikipedia/en/thum...
110 https://upload.wikimedia.org/wikipedia/en/thum...
112 https://upload.wikimedia.org/wikipedia/en/thum...
169 https://upload.wikimedia.org/wikipedia/en/thum...
219 https://upload.wikimedia.org/wikipedia/en/thum...
258 https://upload.wikimedia.org/wikipedia/en/f/fe...
280 NaN
297 https://upload.wikimedia.org/wikipedia/en/thum...
354 https://upload.wikimedia.org/wikipedia/en/thum...
362 https://upload.wikimedia.org/wikipedia/en/thum...
365 https://upload.wikimedia.org/wikipedia/en/thum...
393 https://upload.wikimedia.org/wikipedia/en/thum...
449 https://upload.wikimedia.org/wikipedia/en/thum...
536 https://upload.wikimedia.org/wikipedia/en/thum...
589 https://upload.wikimedia.org/wikipedia/en/thum...
625 https://upload.wikimedia.org/wikipedia/en/thum...
668 https://upload.wikimedia.org/wikipedia/en/thum...
693 https://upload.wikimedia.org/wikipedia/en/thum...
694 https://upload.wikimedia.org/wikipedia/en/thum...
982 https://upload.wikimedia.org/wikipedia/en/thum...
1039 https://upload.wikimedia.org/wikipedia/en/thum...
1058 https://upload.wikimedia.org/wikipedia/en/5/58...
1188 https://upload.wikimedia.org/wikipedia/en/thum...
1293 https://upload.wikimedia.org/wikipedia/en/thum...
1294 https://upload.wikimedia.org/wikipedia/en/thum...
1361 https://upload.wikimedia.org/wikipedia/en/thum...
1432 https://upload.wikimedia.org/wikipedia/en/thum...
1495 https://upload.wikimedia.org/wikipedia/en/thum...
1554 https://upload.wikimedia.org/wikipedia/en/thum...
1607 https://upload.wikimedia.org/wikipedia/en/thum...

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
41 https://en.wikipedia.org/wiki/Family_of_Thakur...
84 https://en.wikipedia.org/wiki/Mukkabaaz
106 https://en.wikipedia.org/wiki/Raazi
110 https://en.wikipedia.org/wiki/Parmanu:_The_Sto...
112 https://en.wikipedia.org/wiki/Bhavesh_Joshi_Su...
169 https://en.wikipedia.org/wiki/The_Ghazi_Attack...
219 https://en.wikipedia.org/wiki/Raagdesh
258 https://en.wikipedia.org/wiki/Saala_Khadoos
280 https://en.wikipedia.org/wiki/Laal_Rang
297 https://en.wikipedia.org/wiki/Udta_Punjab
354 https://en.wikipedia.org/wiki/Dangal_(film)
362 https://en.wikipedia.org/wiki/Bajrangi_Bhaijaan
365 https://en.wikipedia.org/wiki/Baby_(2015_Hindi...
393 https://en.wikipedia.org/wiki/Detective_Byomke...
449 https://en.wikipedia.org/wiki/Titli_(2014_film)
536 https://en.wikipedia.org/wiki/Haider_(film)
589 https://en.wikipedia.org/wiki/Vishwaroop_(Hind...
625 https://en.wikipedia.org/wiki/Madras_Cafe
668 https://en.wikipedia.org/wiki/Paan_Singh_Tomar...
693 https://en.wikipedia.org/wiki/Gangs_of_Wasseypur
694 https://en.wikipedia.org/wiki/Gangs_of_Wasseyp...
982 https://en.wikipedia.org/wiki/Jodhaa_Akbar
1039 https://en.wikipedia.org/wiki/1971_(2007_film)
1058 https://en.wikipedia.org/wiki/Black_Friday_(20...
1188 https://en.wikipedia.org/wiki/Omkara_(2006_film)
1293 https://en.wikipedia.org/wiki/Sarkar_(2005_film)
1294 https://en.wikipedia.org/wiki/Sehar
1361 https://en.wikipedia.org/wiki/Lakshya_(film)
1432 https://en.wikipedia.org/wiki/Gangaajal
1495 https://en.wikipedia.org/wiki/Company_(film)
1554 https://en.wikipedia.org/wiki/The_Legend_of_Bh...
1607 https://en.wikipedia.org/wiki/Nayak_(2001_Hind...

title_y original_title
is_adult \
0 Uri: The Surgical Strike Uri: The Surgical Strike
0
41 Family of Thakurganj Family of Thakurganj
0
84 The Brawler Mukkabaaz
0
106 Raazi Raazi
0
110 Parmanu: The Story of Pokhran Parmanu: The Story of Pokhran
0
112 Bhavesh Joshi Superhero Bhavesh Joshi Superhero
0
169 The Ghazi Attack The Ghazi Attack
0
219 Raag Desh Raag Desh
0
258 Saala Khadoos Saala Khadoos
0
280 Laal Rang Laal Rang
0
297 Udta Punjab Udta Punjab
0
354 Dangal Dangal
0
362 Bajrangi Bhaijaan Bajrangi Bhaijaan
0
365 Baby Baby
0
393 Detective Byomkesh Bakshy! Detective Byomkesh Bakshy!
0
449 Titli Titli
0
536 Haider Haider
0
589 Vishwaroopam Vishwaroopam
0
625 Madras Cafe Madras Cafe
0
668 Paan Singh Tomar Paan Singh Tomar
0
693 Gangs of Wasseypur Gangs of Wasseypur
0
694 Gangs of Wasseypur Gangs of Wasseypur
0
982 Jodhaa Akbar Jodhaa Akbar
0
1039 1971 1971
0
1058 Black Friday Black Friday
0
1188 Omkara Omkara
0
1293 Sarkar Sarkar
0
1294 Sehar Sehar
0
1361 Lakshya Lakshya
0
1432 Gangaajal Gangaajal
0
1495 Company Company
0
1554 The Legend of Bhagat Singh The Legend of Bhagat Singh
0
1607 Nayak: The Real Hero Nayak: The Real Hero
0

year_of_release runtime genres imdb_rating \


0 2019 138 Action|Drama|War 8.4
41 2019 127 Action|Drama 9.4
84 2017 154 Action|Drama|Sport 8.1
106 2018 138 Action|Drama|Thriller 7.8
110 2018 129 Action|Drama|History 7.7
112 2018 154 Action|Drama 7.6
169 2017 116 Action|Thriller|War 7.6
219 2017 135 Action|Drama|History 8.3
258 2016 109 Action|Drama|Sport 7.6
280 2016 147 Action|Crime|Drama 8.0
297 2016 148 Action|Crime|Drama 7.8
354 2016 161 Action|Biography|Drama 8.4
362 2015 163 Action|Comedy|Drama 8.0
365 2015 159 Action|Thriller 8.0
393 2015 139 Action|Mystery|Thriller 7.6
449 2014 116 Action|Drama|Thriller 7.6
536 2014 160 Action|Crime|Drama 8.1
589 2013 148 Action|Thriller 8.2
625 2013 130 Action|Drama|Thriller 7.7
668 2012 135 Action|Biography|Crime 8.2
693 2012 321 Action|Comedy|Crime 8.2
694 2012 321 Action|Comedy|Crime 8.2
982 2008 213 Action|Drama|History 7.6
1039 2007 160 Action|Drama|War 7.9
1058 2004 143 Action|Crime|Drama 8.5
1188 2006 155 Action|Crime|Drama 8.1
1293 2005 124 Action|Crime|Drama 7.6
1294 2005 125 Action|Crime|Drama 7.8
1361 2004 186 Action|Drama|Romance 7.9
1432 2003 157 Action|Crime|Drama 7.8
1495 2002 155 Action|Crime|Drama 8.0
1554 2002 155 Action|Biography|Drama 8.1
1607 2001 187 Action|Drama|Thriller 7.8

imdb_votes story \
0 35112 Divided over five chapters the film chronicle...
41 895 The film is based on small town of North India...
84 5434 A boxer (Shravan) belonging to upper cast tra...
106 20289 Hidayat Khan is the son of an Indian freedom f...
110 18292 Captain Ashwat Raina's efforts to turn India i...
112 4928 Bhavesh Joshi Superhero is an action film abou...
169 10332 In 1971 amid rising tensions between India an...
219 341 A period film based on the historic 1945 India...
258 10507 An under-fire boxing coach Prabhu is transfer...
280 3741 The friendship of two men is tested when thing...
297 23995 What on earth can a rock star a migrant labor...
354 131338 Biopic of Mahavir Singh Phogat who taught wre...
362 65877 A little mute girl from a Pakistani village ge...
365 49426 The country is perpetually under threat from t...
393 14674 CALCUTTA 1943 A WAR - A MYSTERY - and A DETECT...
449 3677 In the badlands of Delhi's dystopic underbelly...
536 46912 Vishal Bhardwaj's adaptation of William Shakes...
589 38016 Vishwanathan a Kathak dance teacher in New Yo...
625 21393 An Indian Intelligence agent (portrayed by Joh...
668 29994 Paan Singh Tomar is a Hindi-language film bas...
693 71636 Shahid Khan is exiled after impersonating the ...
694 71636 Shahid Khan is exiled after impersonating the ...
982 27541 Jodhaa Akbar is a sixteenth century love story...
1039 1121 Based on true facts the film revolves around ...
1058 16761 A dramatic presentation of the bomb blasts tha...
1188 17594 Advocate Raghunath Mishra has arranged the mar...
1293 14694 Meet Subhash Nagre - a wealthy and influential...
1294 1861 At the tender age of 8 Ajay Kumar is traumatiz...
1361 18777 Karan is a lazy good-for-nothing who lives on ...
1432 14295 An SP Amit Kumar who is given charge of Tezpur...
1495 13474 Mallik is a henchman of Aslam Bhai a Mumbai u...
1554 13455 Bhagat was born in British India during the ye...
1607 12522 Employed as a camera-man at a popular televisi...

summary \
0 Indian army special forces execute a covert op...
41 The film is based on small town of North India...
84 A boxer struggles to make his mark in the boxi...
106 A Kashmiri woman agrees to marry a Pakistani a...
110 Ashwat Raina and his teammates arrive in Pokhr...
112 The origin story of Bhavesh Joshi an Indian s...
169 A Pakistani submarine Ghazi plans to secretly...
219 A period film based on the historic 1945 India...
258 The story of a former boxer who quits boxing f...
280 The friendship of two men is tested when thing...
297 A story that revolves around drug abuse in the...
354 Former wrestler Mahavir Singh Phogat and his t...
362 An Indian man with a magnanimous heart takes a...
365 An elite counter-intelligence unit learns of a...
393 While investigating the disappearance of a che...
449 A Hindi feature film set in the lower depths o...
536 A young man returns to Kashmir after his fathe...
589 When a classical dancer's suspecting wife sets...
625 An Indian intelligence agent journeys to a war...
668 The story of Paan Singh Tomar an Indian athle...
693 A clash between Sultan and Shahid Khan leads t...
694 A clash between Sultan and Shahid Khan leads t...
982 A sixteenth century love story about a marriag...
1039 Based on true facts the film revolves around ...
1058 Black Friday is a film about the investigation...
1188 A politically-minded enforcer's misguided trus...
1293 The authority of a man who runs a parallel go...
1294 Ajay Kumar the newly appointed honest SSP of ...
1361 An aimless jobless irresponsible grown man j...
1432 An IPS officer motivates and leads a dysfuncti...
1495 A small-time gangster named Chandu teams up wi...
1554 The story of a young revolutionary who raised ...
1607 A man accepts a challenge by the chief ministe...

tagline \
0 NaN
41 NaN
84 NaN
106 An incredible true story
110 1998| India: one secret operation| six Indians...
112 This year| justice will have a new name.
169 The war you did not know about
219 NaN
258 NaN
280 Every job good or bad| must be done with honesty.
297 NaN
354 You think our girls are any lesser than boys?
362 NaN
365 History Is Made By Those Who Give A Damn!
393 Expect The Unexpected
449 Daring| Desireable| Dangerous
536 NaN
589 NaN
625 NaN
668 NaN
693 NaN
694 NaN
982 NaN
1039 Honor the heroes.......
1058 The story of the Bombay bomb blasts
1188 NaN
1293 'There are no Rights and Wrongs. Only Power' -...
1294 NaN
1361 It took him 24 years and 18000 feet to find hi...
1432 NaN
1495 A law & order enterprise
1554 NaN
1607 Fight the power

actors \
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga...
41 Jimmy Sheirgill|Mahie Gill|Nandish Singh|Prana...
84 Viineet Kumar|Jimmy Sheirgill|Zoya Hussain|Rav...
106 Alia Bhatt|Vicky Kaushal|Rajit Kapoor|Shishir ...
110 John Abraham|Boman Irani|Diana Penty|Anuja Sat...
112 Harshvardhan Kapoor|Priyanshu Painyuli|Ashish ...
169 Rana Daggubati|Kay Kay Menon|Atul Kulkarni|Om ...
219 Kunal Kapoor|Amit Sadh|Mohit Marwah|Kenneth De...
258 Madhavan|Ritika Singh|Mumtaz Sorcar|Nassar|Rad...
280 Randeep Hooda|Akshay Oberoi|Rajniesh Duggall|P...
297 Shahid Kapoor|Alia Bhatt|Kareena Kapoor|Diljit...
354 Aamir Khan|Fatima Sana Shaikh|Sanya Malhotra|S...
362 Salman Khan|Harshaali Malhotra|Nawazuddin Sidd...
365 Akshay Kumar|Danny Denzongpa|Rana Daggubati|Ta...
393 Sushant Singh Rajput|Anand Tiwari|Neeraj Kabi|...
449 Nawazuddin Siddiqui|Niharika Singh|Anil George...
536 Tabu|Shahid Kapoor|Shraddha Kapoor|Kay Kay Men...
589 Kamal Haasan|Rahul Bose|Shekhar Kapur|Pooja Ku...
625 John Abraham|Nargis Fakhri|Raashi Khanna|Praka...
668 Irrfan Khan|
693 Manoj Bajpayee|Richa Chadha|Nawazuddin Siddiqu...
694 Manoj Bajpayee|Richa Chadha|Nawazuddin Siddiqu...
982 Hrithik Roshan|Aishwarya Rai Bachchan|Sonu Soo...
1039 Manoj Bajpayee|Ravi Kishan|Deepak Dobriyal|
1058 Kay Kay Menon|Pavan Malhotra|Aditya Srivastava...
1188 Ajay Devgn|Saif Ali Khan|Vivek Oberoi|Kareena ...
1293 Amitabh Bachchan|Abhishek Bachchan|Kay Kay Men...
1294 Arshad Warsi|Pankaj Kapur|Mahima Chaudhry|Sush...
1361 Hrithik Roshan|Preity Zinta|Amitabh Bachchan|O...
1432 Ajay Devgn|Gracy Singh|Mohan Joshi|Yashpal Sha...
1495 Ajay Devgn|Mohanlal|Manisha Koirala|Seema Bisw...
1554 Ajay Devgn|Sushant Singh|D. Santosh|Akhilendra...
1607 Anil Kapoor|Rani Mukerji|Amrish Puri|Johnny Le...

wins_nominations release_date
0 4 wins 11 January 2019 (USA)
41 NaN 19 July 2019 (India)
84 3 wins & 6 nominations 12 January 2018 (USA)
106 21 wins & 26 nominations 11 May 2018 (USA)
110 NaN 25 May 2018 (USA)
112 2 nominations 1 June 2018 (USA)
169 1 win & 7 nominations 17 February 2017 (USA)
219 NaN 28 July 2017 (India)
258 9 wins & 2 nominations 29 January 2016 (USA)
280 NaN 22 April 2016 (India)
297 11 wins & 19 nominations 17 June 2016 (USA)
354 23 wins & 4 nominations 21 December 2016 (USA)
362 25 wins & 13 nominations 17 July 2015 (USA)
365 1 win 23 January 2015 (India)
393 NaN 3 April 2015 (USA)
449 4 wins & 5 nominations 20 June 2014 (USA)
536 28 wins & 24 nominations 2 October 2014 (USA)
589 5 wins & 11 nominations 25 January 2013 (India)
625 10 wins & 10 nominations 23 August 2013 (India)
668 10 wins & 11 nominations 2 March 2012 (USA)
693 12 wins & 43 nominations 2 August 2012 (Singapore)
694 12 wins & 43 nominations 2 August 2012 (Singapore)
982 32 wins & 21 nominations 15 February 2008 (USA)
1039 1 win 9 March 2007 (India)
1058 3 nominations 9 February 2007 (India)
1188 19 wins & 20 nominations 28 July 2006 (USA)
1293 2 wins & 10 nominations 1 July 2005 (India)
1294 NaN 29 July 2005 (India)
1361 4 wins & 10 nominations 18 June 2004 (USA)
1432 4 wins & 29 nominations 29 August 2003 (India)
1495 16 wins & 9 nominations 15 April 2002 (India)
1554 11 wins & 5 nominations 7 June 2002 (India)
1607 2 nominations 7 September 2001 (India)

# write a function that can return the track record of 2 teams against
each other

Adding new cols


# completely new
movies['Country'] = 'India'
movies.head()

title_x imdb_id \
0 Uri: The Surgical Strike tt8291224
1 Battalion 609 tt9472208
2 The Accidental Prime Minister (film) tt6986710
3 Why Cheat India tt8108208
4 Evening Shadows tt6028796

poster_path \
0 https://upload.wikimedia.org/wikipedia/en/thum...
1 NaN
2 https://upload.wikimedia.org/wikipedia/en/thum...
3 https://upload.wikimedia.org/wikipedia/en/thum...
4 NaN

wiki_link \
0 https://en.wikipedia.org/wiki/Uri:_The_Surgica...
1 https://en.wikipedia.org/wiki/Battalion_609
2 https://en.wikipedia.org/wiki/The_Accidental_P...
3 https://en.wikipedia.org/wiki/Why_Cheat_India
4 https://en.wikipedia.org/wiki/Evening_Shadows

title_y original_title
is_adult \
0 Uri: The Surgical Strike Uri: The Surgical Strike
0
1 Battalion 609 Battalion 609
0
2 The Accidental Prime Minister The Accidental Prime Minister
0
3 Why Cheat India Why Cheat India
0
4 Evening Shadows Evening Shadows
0

year_of_release runtime genres imdb_rating imdb_votes


\
0 2019 138 Action|Drama|War 8.4 35112

1 2019 131 War 4.1 73

2 2019 112 Biography|Drama 6.1 5549

3 2019 121 Crime|Drama 6.0 1891

4 2018 102 Drama 7.3 280

story \
0 Divided over five chapters the film chronicle...
1 The story revolves around a cricket match betw...
2 Based on the memoir by Indian policy analyst S...
3 The movie focuses on existing malpractices in ...
4 While gay rights and marriage equality has bee...
summary tagline \
0 Indian army special forces execute a covert op... NaN
1 The story of Battalion 609 revolves around a c... NaN
2 Explores Manmohan Singh's tenure as the Prime ... NaN
3 The movie focuses on existing malpractices in ... NaN
4 Under the 'Evening Shadows' truth often plays... NaN

actors
wins_nominations \
0 Vicky Kaushal|Paresh Rawal|Mohit Raina|Yami Ga...
4 wins
1 Vicky Ahuja|Shoaib Ibrahim|Shrikant Kamat|Elen...
NaN
2 Anupam Kher|Akshaye Khanna|Aahana Kumra|Atul S...
NaN
3 Emraan Hashmi|Shreya Dhanwanthary|Snighdadeep ...
NaN
4 Mona Ambegaonkar|Ananth Narayan Mahadevan|Deva... 17 wins & 1
nomination

release_date Country
0 11 January 2019 (USA) India
1 11 January 2019 (India) India
2 11 January 2019 (USA) India
3 18 January 2019 (USA) India
4 11 January 2019 (India) India

# from existing ones


movies.dropna(inplace=True)

movies['lead actor'] = movies['actors'].str.split('|').apply(lambda


x:x[0])
movies.head()

title_x imdb_id \
11 Gully Boy tt2395469
34 Yeh Hai India tt5525846
37 Article 15 (film) tt10324144
87 Aiyaary tt6774212
96 Raid (2018 film) tt7363076

poster_path \
11 https://upload.wikimedia.org/wikipedia/en/thum...
34 https://upload.wikimedia.org/wikipedia/en/thum...
37 https://upload.wikimedia.org/wikipedia/en/thum...
87 https://upload.wikimedia.org/wikipedia/en/thum...
96 https://upload.wikimedia.org/wikipedia/en/thum...

wiki_link title_y \
11 https://en.wikipedia.org/wiki/Gully_Boy Gully Boy
34 https://en.wikipedia.org/wiki/Yeh_Hai_India Yeh Hai India
37 https://en.wikipedia.org/wiki/Article_15_(film) Article 15
87 https://en.wikipedia.org/wiki/Aiyaary Aiyaary
96 https://en.wikipedia.org/wiki/Raid_(2018_film) Raid

original_title is_adult year_of_release runtime


genres \
11 Gully Boy 0 2019 153
Drama|Music
34 Yeh Hai India 0 2017 128 Action|
Adventure|Drama
37 Article 15 0 2019 130
Crime|Drama
87 Aiyaary 0 2018 157 Action|
Thriller
96 Raid 0 2018 122 Action|
Crime|Drama

imdb_rating imdb_votes \
11 8.2 22440
34 5.7 169
37 8.3 13417
87 5.2 3538
96 7.4 13159

story \
11 Gully Boy is a film about a 22-year-old boy "M...
34 Yeh Hai India follows the story of a 25 years...
37 In the rural heartlands of India an upright p...
87 General Gurinder Singh comes with a proposal t...
96 Set in the 80s in Uttar Pradesh India Raid i...

summary \
11 A coming-of-age story based on the lives of st...
34 Yeh Hai India follows the story of a 25 years...
37 In the rural heartlands of India an upright p...
87 After finding out about an illegal arms deal ...
96 A fearless income tax officer raids the mansio...

tagline \
11 Apna Time Aayega!
34 A Film for Every Indian
37 Farq Bahut Kar Liya| Ab Farq Laayenge.
87 The Ultimate Trickery
96 Heroes don't always come in uniform

actors
wins_nominations \
11 Ranveer Singh|Alia Bhatt|Siddhant Chaturvedi|V... 6 wins & 3
nominations
34 Gavie Chahal|Mohan Agashe|Mohan Joshi|Lom Harsh| 2 wins & 1
nomination
37 Ayushmann Khurrana|Nassar|Manoj Pahwa|Kumud Mi...
1 win
87 Sidharth Malhotra|Manoj Bajpayee|Rakul Preet S... 1
nomination
96 Ajay Devgn|Saurabh Shukla|Ileana D'Cruz|Amit S... 2 wins & 3
nominations

release_date Country lead actor


11 14 February 2019 (USA) India Ranveer Singh
34 24 May 2019 (India) India Gavie Chahal
37 28 June 2019 (USA) India Ayushmann Khurrana
87 16 February 2018 (USA) India Sidharth Malhotra
96 16 March 2018 (India) India Ajay Devgn

movies.info()

<class 'pandas.core.frame.DataFrame'>
Int64Index: 298 entries, 11 to 1623
Data columns (total 19 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 title_x 298 non-null object
1 imdb_id 298 non-null object
2 poster_path 298 non-null object
3 wiki_link 298 non-null object
4 title_y 298 non-null object
5 original_title 298 non-null object
6 is_adult 298 non-null int64
7 year_of_release 298 non-null int64
8 runtime 298 non-null object
9 genres 298 non-null object
10 imdb_rating 298 non-null float64
11 imdb_votes 298 non-null int64
12 story 298 non-null object
13 summary 298 non-null object
14 tagline 298 non-null object
15 actors 298 non-null object
16 wins_nominations 298 non-null object
17 release_date 298 non-null object
18 Country 298 non-null object
dtypes: float64(1), int64(3), object(15)
memory usage: 46.6+ KB

Important DataFrame Functions


# astype
ipl.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 950 entries, 0 to 949
Data columns (total 20 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 950 non-null int64
1 City 899 non-null object
2 Date 950 non-null object
3 Season 950 non-null object
4 MatchNumber 950 non-null object
5 Team1 950 non-null object
6 Team2 950 non-null object
7 Venue 950 non-null object
8 TossWinner 950 non-null object
9 TossDecision 950 non-null object
10 SuperOver 946 non-null object
11 WinningTeam 946 non-null object
12 WonBy 950 non-null object
13 Margin 932 non-null float64
14 method 19 non-null object
15 Player_of_Match 946 non-null object
16 Team1Players 950 non-null object
17 Team2Players 950 non-null object
18 Umpire1 950 non-null object
19 Umpire2 950 non-null object
dtypes: float64(1), int64(1), object(18)
memory usage: 148.6+ KB

ipl['ID'] = ipl['ID'].astype('int32')

ipl.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 950 entries, 0 to 949
Data columns (total 20 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 950 non-null int32
1 City 899 non-null object
2 Date 950 non-null object
3 Season 950 non-null object
4 MatchNumber 950 non-null object
5 Team1 950 non-null object
6 Team2 950 non-null object
7 Venue 950 non-null object
8 TossWinner 950 non-null object
9 TossDecision 950 non-null object
10 SuperOver 946 non-null object
11 WinningTeam 946 non-null object
12 WonBy 950 non-null object
13 Margin 932 non-null float64
14 method 19 non-null object
15 Player_of_Match 946 non-null object
16 Team1Players 950 non-null object
17 Team2Players 950 non-null object
18 Umpire1 950 non-null object
19 Umpire2 950 non-null object
dtypes: float64(1), int32(1), object(18)
memory usage: 144.9+ KB

# ipl['Season'] = ipl['Season'].astype('category')
ipl['Team1'] = ipl['Team1'].astype('category')
ipl['Team2'] = ipl['Team2'].astype('category')

ipl.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 950 entries, 0 to 949
Data columns (total 20 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 950 non-null int32
1 City 899 non-null object
2 Date 950 non-null object
3 Season 950 non-null category
4 MatchNumber 950 non-null object
5 Team1 950 non-null category
6 Team2 950 non-null category
7 Venue 950 non-null object
8 TossWinner 950 non-null object
9 TossDecision 950 non-null object
10 SuperOver 946 non-null object
11 WinningTeam 946 non-null object
12 WonBy 950 non-null object
13 Margin 932 non-null float64
14 method 19 non-null object
15 Player_of_Match 946 non-null object
16 Team1Players 950 non-null object
17 Team2Players 950 non-null object
18 Umpire1 950 non-null object
19 Umpire2 950 non-null object
dtypes: category(3), float64(1), int32(1), object(15)
memory usage: 127.4+ KB

# value_counts

# find which player has won most potm -> in finals and qualifiers

# Toss decision plot


# how many matches each team has played

# sort_values -> ascending -> na_position -> inplace -> multiple cols

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy