0% found this document useful (0 votes)
3 views49 pages

Pandas

The document provides an overview of the Pandas library in Python, focusing on its data structures, specifically Series and DataFrame. It covers key attributes, common methods for data manipulation, handling missing data, and indexing techniques. Additionally, it includes examples of creating Series and DataFrames, performing aggregation, and merging datasets.

Uploaded by

baluduvamsi2000
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)
3 views49 pages

Pandas

The document provides an overview of the Pandas library in Python, focusing on its data structures, specifically Series and DataFrame. It covers key attributes, common methods for data manipulation, handling missing data, and indexing techniques. Additionally, it includes examples of creating Series and DataFrames, performing aggregation, and merging datasets.

Uploaded by

baluduvamsi2000
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/ 49

keyboard_arrow_down Importing Pandas

import pandas as pd
import numpy as np

Pandas

Pandas is a powerful Python library for data manipulation and analysis. It provides easy-to-use
data structures and functions to work with structured data like tabular, time series, or matrix data.

Pandas primarily provides two data structures: Series and DataFrame.

Series: A one-dimensional labeled array capable of holding any data type.

DataFrame: A two-dimensional labeled data structure with columns of potentially different types.

Pandas - Series

Series in pandas is a fundamental data structure that represents a one-dimensional array of


indexed data. It can hold any type of data—integers, strings, floats, Python objects, etc. The Series
object is built on top of the NumPy array and is very similar to it but with additional capabilities like
handling missing data. The indices of a pandas Series are more flexible than those in a simple
NumPy array.

keyboard_arrow_down Creating a Series


s = pd.Series([1, 3, 5, 7, 9])
print(s)

0 1
1 3
2 5
3 7
4 9
dtype: int64

Key Attributes

Values: The data in the Series.


Index: The index (labels) of each data point.

Common Methods of Series

keyboard_arrow_down Descriptive Statistics


s.describe(): Provides a quick summary of the data.

This method gives a statistical summary of the Series, including count, mean, standard deviation,
minimum, maximum, and quartile values.

# Creating a Series
s = pd.Series([1, 3, 5, 7, 9])

# Descriptive statistics
print(s.describe())

count 5.000000
mean 5.000000
std 3.162278
min 1.000000
25% 3.000000
50% 5.000000
75% 7.000000
max 9.000000
dtype: float64

s.mean(): Computes the mean of the data.

# Mean of the Series


print(s.mean())

5.0

s.std(): Computes the standard deviation.

# Standard deviation of the Series


print(s.std())

3.1622776601683795

s.min() and s.max(): Computes the minimum and maximum values.


# Minimum and maximum values
print(s.min())
print(s.max())

1
9

keyboard_arrow_down Data Manipulation


s.map(func): Applies a function to each element in the Series.

# Mapping function to double the values


doubled = s.map(lambda x: x * 2)
print(doubled)

0 2
1 6
2 10
3 14
4 18
dtype: int64

s.apply(func): Similar to map, but more flexible. (Can be used Data Frames as well, where as map
is only for Series)

# Applying a function to calculate square root


sqrt = s.apply(lambda x: x ** 0.5)
print(sqrt)

0 1.000000
1 1.732051
2 2.236068
3 2.645751
4 3.000000
dtype: float64

s.sort_values(): Sorts the Series.

# Sorting the Series


sorted_s = s.sort_values()
print(sorted_s)

0 1
1 3
2 5
3 7
4 9
dtype: int64

s.drop(labels): Drops specified labels from the Series.

# Dropping the first element


dropped = s.drop(0)
print(dropped)

1 3
2 5
3 7
4 9
dtype: int64

print(s)

0 1
1 3
2 5
3 7
4 9
dtype: int64

keyboard_arrow_down Handling Missing Data


s.isnull(): Checks for missing values, returns a Series of booleans.

# Checking for missing values


print(s.isnull())

0 False
1 False
2 False
3 False
4 False
dtype: bool

s.notnull(): Opposite of isnull().

# Checking for non-null values


print(s.notnull())

0 True
1 True
2 True
3 True
4 True
dtype: bool

s.fillna(value): Fills missing values with a specified value.

# Create a Series with missing values


s = pd.Series([1, 2, np.nan, 4, np.nan])

# Print the Series


print(s)

0 1.0
1 2.0
2 NaN
3 4.0
4 NaN
dtype: float64

# Filling missing values with 0


filled = s.fillna(9)
print(filled)

0 1.0
1 2.0
2 9.0
3 4.0
4 9.0
dtype: float64

s.dropna(): Drops all rows that contain missing values.

# Creating a Series with missing values


s_with_missing = pd.Series([1, 2, None, 4, 5])

# Dropping missing values


dropped_missing = s_with_missing.dropna()
print(dropped_missing)

0 1.0
1 2.0
3 4.0
4 5.0
dtype: float64

keyboard_arrow_down Indexing, Slicing, and Filtering


s.iloc[ ]: Purely integer-location based indexing.
# Indexing by position
s = pd.Series([1, 3, 5, 7, 9])
print(s.iloc[0]) # First element
print(s.iloc[-1]) # Last element

1
9

s.loc[ ]: Label-based indexing.

# Indexing by label
print(s.loc[0]) # First element
print(s.loc[4]) # Last element

1
9

# Create a Series
s = pd.Series([10, 20, 30, 40], index=['a', 'b', 'c', 'd'])
print(s)
# Accessing elements using iloc
print(s.iloc[0]) # Access the first element
print(s.iloc[1:3]) # Access elements at positions 1 and 2 (exclusive of 3)

# Accessing elements using loc


print(s.loc['a']) # Access the element with index label 'a'
print(s.loc['b':'c']) # Access elements with index labels 'b' and 'c'

a 10
b 20
c 30
d 40
dtype: int64
10
b 20
c 30
dtype: int64
10
b 20
c 30
dtype: int64

s[s > n]: Filters and returns elements greater than n.

# Filtering elements greater than 5


filtered = s[s > 5]
print(filtered)

3 7
4 9
dtype: int64
keyboard_arrow_down Aggregation
s.sum(): Sums up the values.

# Sum of the Series


print(s.sum())

25

s.cumsum(): Cumulative sum.

# Cumulative sum of the Series


print(s)
print(s.cumsum())

0 1
1 3
2 5
3 7
4 9
dtype: int64
0 1
1 4
2 9
3 16
4 25
dtype: int64

s.aggregate(func): Aggregates using one or more operations.

# Aggregating using multiple operations


aggregated = s.aggregate(['sum', 'mean', 'std'])
print(aggregated)

sum 25.000000
mean 5.000000
std 3.162278
dtype: float64

keyboard_arrow_down Creating Data Frame


# Define data
data = {
'Name': ['Dodagatta Nihar', 'Vignesh', 'Maheshwar', 'Naman', 'Naveen', 'Shreya', 'Varsh
'Role': ['Founder', 'Growth Manager', 'Community Manager', 'Community Manager', 'Commun
'Course Designer', 'Course Designer', 'Public Relations Manager'],
'Phone Number': ['111-111-1111', '222-222-2222', '333-333-3333', '444-444-4444',
'555-555-5555', '666-666-6666', '777-777-7777', '888-888-8888'],
'Email': ['nihar@masscoders.tech', 'vignesh@masscoders.tech', 'maheshwar@masscoders.tec
'naveen@masscoders.tech', 'shreya@masscoders.tech', 'varsha@masscoders.tech',
'Address': ['123, MG Road, Bangalore', '456, Brigade Road, Chennai', '789, Rajaji Nagar
'202, Koramangala, Hyderabad', '303, JP Nagar, Kolkata', '404, Electronic C
'Blood Group': ['A+', 'B-', 'O+', 'AB+', 'A-', 'B+', 'O-', 'AB-']
}

# Create DataFrame
team_mass_coders_df = pd.DataFrame(data)

# Display DataFrame
team_mass_coders_df.head()

Phone Blood
Name Role Number Email Address Group
Dodagatta 111-111- 123, MG Road,
0 Founder nihar@masscoders.tech A+
Nihar 1111 Bangalore

Growth 222-222- 456, Brigade


1 Vignesh vignesh@masscoders.tech B-
Manager 2222 Road, Chennai

Community 333-333- 789, Rajaji


2 Maheshwar maheshwar@masscoders.tech O+
Manager 3333 Nagar, Mumbai

Community 444-444- 101, Indira


3 Naman naman@masscoders.tech AB+
team_mass_coders_df Manager 4444 Nagar, Delhi

202,
Community Phone
555-555- Blood
4 Name
Naveen Role
Manager Number
5555
Email
naveen@masscoders.tech Address
Koramangala, A-
Group
Hyderabad

Dodagatta 111-111- 123, MG Road,


0 Founder nihar@masscoders.tech A+
Nihar 1111 Bangalore

Growth 222-222- 456, Brigade


1 Vignesh vignesh@masscoders.tech B-
Manager 2222 Road, Chennai

Community 333-333- 789, Rajaji


2 Maheshwar maheshwar@masscoders.tech O+
Manager 3333 Nagar, Mumbai

Community 444-444- 101, Indira


3 Naman naman@masscoders.tech AB+
Manager 4444 Nagar, Delhi

202,
Community 555-555-
4 Naveen naveen@masscoders.tech Koramangala, A-
Manager 5555
Hyderabad

keyboard_arrow_down Merging
5 Shreya
Course
Data Designer
Frames 6666
666-666-
shreya@masscoders.tech
303, JP Nagar,
Kolkata
B+

Course 777-777- 404, Electronic


6 Varsha varsha@masscoders.tech O-
Designer 7777 City, Pune
# Team roles data
roles_data = { Public 505, HSR
888-888-
'Name': ['Dodagatta Nihar', 'Vignesh', 'Maheshwar', 'Naman', 'Naveen', 'Shreya', 'Varsh
7 Varun Relations varun@masscoders.tech Layout, AB-
8888 'Community Manager', 'Community Manager', 'Commun
'Role': ['Founder', 'Growth Manager',
Manager Ahmedabad
'Course Designer', 'Course Designer', 'Public Relations Manager']
}

roles_df = pd.DataFrame(roles_data)

# Contact information data


contact_data = {
'Name': ['Dodagatta Nihar', 'Vignesh', 'Maheshwar', 'Naman', 'Naveen', 'Shreya', 'Varsh
'Phone Number': ['111-111-1111', '222-222-2222', '333-333-3333', '444-444-4444',
'555-555-5555', '666-666-6666', '777-777-7777', '888-888-8888'],
'Email': ['nihar@masscoders.tech', 'vignesh@masscoders.tech', 'maheshwar@masscoders.tec
'naveen@masscoders.tech', 'shreya@masscoders.tech', 'varsha@masscoders.tech',
}

contact_df = pd.DataFrame(contact_data)

merged_df = pd.merge(roles_df, contact_df, on='Name')

merged_df

Name Role Phone Number Email


0 Dodagatta Nihar Founder 111-111-1111 nihar@masscoders.tech

1 Vignesh Growth Manager 222-222-2222 vignesh@masscoders.tech

2 Maheshwar Community Manager 333-333-3333 maheshwar@masscoders.tech

3 Naman Community Manager 444-444-4444 naman@masscoders.tech

4 Naveen Community Manager 555-555-5555 naveen@masscoders.tech

5 Shreya Course Designer 666-666-6666 shreya@masscoders.tech

6 Varsha Course Designer 777-777-7777 varsha@masscoders.tech

7 Varun Public Relations Manager 888-888-8888 varun@masscoders.tech

keyboard_arrow_down Importing Dataset


Importing datasets into Pandas is straightforward, and Pandas supports various file formats like
csv, xlsx, json, sql etc.

df = pd.read_csv('filmtv_movies.csv')

# Display the first few rows of the DataFrame to understand its structure and contents
df.head()
filmtv_id title year genre duration country directors actors avg
Bugs
Bunny's
David
Third
United Detiege, Art
0 2 Movie: 1982 Animation 76 NaN
States Davis, Bill
1001
Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni
Simona
1 3 tra una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a United Don
2 17 1976 Romantic 91 Meillon,
Wild Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 Diner 1982 Comedy 95
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
4 20 1942 Comedy 85 Italy Peppino De
questi Pratelli
Filippo,
quattrini?
Clelia...

The dataset contains information about movies, represented in a DataFrame structure.

filmtv_id: A unique identifier for each movie.

title: The title of the movie.

year: The release year of the movie.

genre: The genre of the movie.

duration: The duration of the movie in minutes.

country: The country where the movie was produced.

directors: Names of the directors of the movie.

actors: Names of the main actors in the movie.


avg_vote, critics_vote, public_vote: Average ratings from different sources.

total_votes: Total number of votes the movie received.

description: A short description of the movie plot.

notes: Additional notes or commentary about the movie.

humor, rhythm, effort, tension, erotism: Various attributes rated on a scale (probably from 0 to a
maximum value, representing different aspects of the movie).

Pandas - DataFrame

keyboard_arrow_down Properties of DataFrame


df.head(n): The df.head(n) method is used to view the first n rows of the DataFrame. This is
particularly useful for getting a quick snapshot of the data, especially to understand the structure
and the types of data contained in each column. If you don't specify n, the default number of rows
displayed is 5.

df.head(10) # Displays the first 10 rows of the DataFrame


filmtv_id title year genre duration country directors actors
Bugs
Bunny's
Third David Detiege,
United
0 2 Movie: 1982 Animation 76 Art Davis, Bill NaN
States
1001 Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni tra
Simona
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a Wild United
2 17 1976 Romantic 91 Don Chaffey Meillon,
Pony States
Eva Griffith,
Gra...

Mickey
Rourke,
United Steve
3 18 Diner 1982 Comedy 95 Barry Levinson
States Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono
4 20 1942 Comedy 85 Italy Esodo Pratelli Peppino De
questi
Filippo,
quattrini?
Clelia...

Fabio Testi,
Gianfranco Janet
The Italy,
Baldanello, Agren,
5 21 Uranian 1978 Spy 117 Germany,
Menahem Assaf
Conspiracy Israel
Golan Dayan,
Siegfri...

Gian Maria
Volonté,
A ciascuno Irene
6 22 1967 Drama 93 Italy Elio Petri
il suo Papas,
Gabriele
Ferz...

Don
Johnson,
United John Penelope
7 23 Dead-Bang 1989 Crime 109
States Frankenheimer Ann Miller,
William
Fors...

Alan Steel
Alan Steel,
Mary
Ray Morrison
A... come Arden,
8 24 1966 Thriller 80 Italy (Angelo
df.tail(n): The df.tail(n)assassino
method is similar to df.head(n) but for the end of the DataFrame. It returns
Sergio
Dorigo)
Ciani, Ivano
the last n rows. This is useful to see the most recent or the last few entries in your data, depending
Da...
on the ordering of your dataset. Like df.head(n), the default value of n is 5 if it isn't specified.
Christopher
Walken,
At Close United
df.tail(10)
9 # Displays
26 the last 10 rowsDrama
1986 of the DataFrame
115 James Foley Sean Penn,
Range States
Chris Penn,
Mar...
filmtv_id title year genre duration country directors actors
Anna
Castillo
41389 232184 Nowhere 2023 Thriller 109 Spain Albert Pintó
Tama
Novas

Martin
Loeb
Mes petites Jean Jacqueline
41390 232203 1974 Drama 123 France
amoureuses Eustache Dufranne
Jacques
Roma..

Zoé De
Grand
Michael Maison
United
41391 232755 Organ Trail 2023 Western 112 Patrick Mathe
States
Jann Zickel
Lisa
LoCic..

Alex
Paxton
Hidden Beesley
Stefan
41392 232757 Family 2021 Thriller 87 Canada Madelyn
Brogren
Secrets Keys
Sonja
Smits..

Alessio
Vassallo
La stoccata Nicola Flavio
41393 232816 2023 Biography 107 Italy
vincente Campiotti Insinna
Elena
Funari..

Julie Benz
Roan
Canada,
Gold Digger Curtis
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georgia
States
Bradner
Eli ..

Laura
Chiatti
Addio al Francesco Chiara
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francini
Antonia
Liskov..

Katia
Winter
Eva
Patrik
41396 232915 Konferensen 2023 Horror 100 Sweden Melander
Eklund
Lola
Zackow
Ad
Adam ..

Jeon
df.shape: The df.shape attribute of a DataFrame returns a tuple representing the dimensionality of
Jong-seo
South Chung-
41397 232919 Ballelina 2023 Thriller 92 Park Yu
the DataFrame. The first element of the tuple is the number of rows, andKorea
the second is Lee
Hyun the number
rim, Ji-hun
of columns. This is useful when you need to know how large the dataset is, such as when you are Kim
preprocessing data or ensuring that data manipulations have executed correctly. Maribe
Verdú
Invitación a
J.M Stephanie
df.shape
41398# Outputs: (number of rows,
232920 number Thriller
un 2023 of columns) 92 Mexico
Cravioto Cayo
Asesinato
Manolo
(41399, 19)
Cardona,..

df.columns: The df.columns attribute returns an Index object containing the column labels of the
DataFrame. Knowing the column names is essential for accessing specific data in the DataFrame,
performing analyses, and for data manipulation tasks like sorting, filtering, or applying functions to
certain columns.

df.columns # Lists all the column names in the DataFrame

Index(['filmtv_id', 'title', 'year', 'genre', 'duration', 'country',


'directors', 'actors', 'avg_vote', 'critics_vote', 'public_vote',
'total_votes', 'description', 'notes', 'humor', 'rhythm', 'effort',
'tension', 'erotism'],
dtype='object')

Inspecting Data Types: Each column in a DataFrame has a specific data type. Understanding these
types is crucial for proper data manipulation

# Display the data types of each column


df.dtypes

filmtv_id int64
title object
year int64
genre object
duration int64
country object
directors object
actors object
avg_vote float64
critics_vote float64
public_vote float64
total_votes int64
description object
notes object
humor int64
rhythm int64
effort int64
tension int64
erotism int64
dtype: object

Summary Statistics: For numerical data, it's useful to get a sense of their central tendency and
spread

# Display summary statistics for numerical columns


df.describe()

filmtv_id year duration avg_vote critics_vote public_vot


count 41399.000000 41399.000000 41399.000000 41399.000000 36703.000000 41205.0000

mean 57746.410179 1993.505302 100.537163 5.801522 5.796077 5.9241

std 59962.095730 23.685612 27.260962 1.403861 1.593062 1.4801

min 2.000000 1897.000000 41.000000 1.000000 1.000000 1.0000

25% 15857.000000 1976.000000 90.000000 4.800000 4.670000 5.0000

50% 36266.000000 2001.000000 96.000000 5.900000 6.000000 6.0000

75% 70935.000000 2013.000000 107.000000 6.900000 7.000000 7.0000

max 232920.000000 2023.000000 1525.000000 10.000000 10.000000 10.0000

keyboard_arrow_down Accessing and Filtering:


df.loc: The df.loc method is used for label-based indexing, meaning you can access rows and
columns using their labels (i.e., index names and column names). It allows for selecting a subset of
rows and columns from a DataFrame with powerful and flexible slicing, indexing, and filtering
options.

df.head(5)
filmtv_id title year genre duration country directors actors avg
Bugs
Bunny's
David
Third
United Detiege, Art
0 2 Movie: 1982 Animation 76 NaN
States Davis, Bill
1001
Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni
Simona
1 3 tra una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a United Don
2 17 1976 Romantic 91 Meillon,
Wild Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 Diner 1982 Comedy 95
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
4 20 1942 Comedy 85 Italy Peppino De
questi Pratelli
Filippo,
quattrini?
Clelia...

# Selecting all rows and a specific column by label


titles = df.loc[:, 'title']
titles

0 Bugs Bunny's Third Movie: 1001 Rabbit Tales


1 18 anni tra una settimana
2 Ride a Wild Pony
3 Diner
4 A che servono questi quattrini?
...
41394 Gold Digger Killer
41395 Addio al nubilato 2
41396 Konferensen
41397 Ballelina
41398 Invitación a un Asesinato
Name: title, Length: 41399, dtype: object
# Selecting a range of rows and multiple columns by labels
subset = df.loc[10:20, ['title', 'year', 'genre']]
subset

title year genre


10 A Ghentar si muore facile 1968 Adventure

11 Sleeping with the Enemy 1990 Drama

12 In Bed With Madonna 1990 Documentary

13 Bowery at Midnight 1942 Horror

14 A mezzanotte va la ronda del piacere 1975 Comedy

15 Mr. Majestyk 1974 Action

16 Warning Sign 1985 Action

17 About Last Night 1986 Comedy

18 Fail-Safe 1964 Drama

19 Some Like It Hot 1959 Comedy

20 A qualsiasi prezzo 1968 Adventure

# Conditional selection using a boolean array


dramas = df.loc[df['genre'] == 'Drama']
dramas
filmtv_id title year genre duration country directors actors
Kim Rossi
Stuart,
18 anni tra
Simona
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Gian Maria
Volonté,
A ciascuno Irene
6 22 1967 Drama 93 Italy Elio Petri
il suo Papas,
Gabriele
Ferz...

Christopher
Walken,
At Close United James
9 26 1986 Drama 115 Sean Penn,
Range States Foley
Chris Penn,
Mar...

Julia
Roberts,
Sleeping
United Joseph Patrick
11 32 with the 1990 Drama 96
States Ruben Bergin,
Enemy
Kevin
Anderson,...

Henry
Fonda, Dan
United Sidney O'Herlihy,
18 49 Fail-Safe 1964 Drama 110
States Lumet Walter
Matthau,
Do...

... ... ... ... ... ... ... ... ...

Turkey,
Tülin Özen,
Tereddüt France, Selman
41368 229838 2023 Drama 84 Görkem
Çizgisi Romania, Nacar
Ipek
Spain

Abhishek
Banerjee,
Karan Harish
41370 229865 Stolen 2023 Drama 92 India
Tejpal Khanna,
Mia
Maelzer,...

Péter Turi,
Dorka
41371 229881 Árni 2023 Drama 103 Hungary Andrea
Vermes
Spolarics

An Ogawa,
Yûko
Kanata no Kyoshi
41372 229883 2023 Drama 84 Japan Nakamura
41372 229883 2023 Drama 84 Japan Nakamura,
uta Sugita
Hidekazu
Mashima
multiple_condition = df.loc[(df['genre'] == 'Drama') & (df['avg_vote']>7.0)]
multiple_condition Martin
Loeb,
Mes petites Jean Jacqueline
41390 232203 1974 Drama 123 France
amoureuses Eustache Dufranne,
Jacques
Roma...

12003 rows × 19 columns


filmtv_id title year genre duration country directors actors
Gian Maria
Volonté,
A ciascuno Irene
6 22 1967 Drama 93 Italy Elio Petri
il suo Papas,
Gabriele
Ferz...

Christopher
Walken,
At Close United James
9 26 1986 Drama 115 Sean Penn,
Range States Foley
Chris Penn,
Mar...

Henry
Fonda, Dan
United Sidney O'Herlihy,
18 49 Fail-Safe 1964 Drama 110
States Lumet Walter
Matthau,
Do...

Justine
Bateman,
Can You
United Michael Jason
30 70 Feel Me 1986 Drama 120
States Miller Bateman,
Dancing?
Max Gail,
Joe ...

Franco
Citti,
Pier Paolo Franca
44 92 Accattone 1961 Drama 120 Italy
Pasolini Pasut,
Adriana
Asti, Paol...

... ... ... ... ... ... ... ... ...

Elisa
Andrade,
Jean
Angola, Sarah
41320 226639 Sambizanga 1972 Drama 97 M'Vondo,
France Maldoror
Dino
Abelino,
Ben...

Bill Camp,
Jamie
United Maggie Foxx,
41349 229784 The Burial 2023 Drama 126
States Betts Tommy
Lee Jones,
Alan R...

Hitoshi
Omika, Ryo
Aku wa
Ryûsuke Nishikawa,
41355 229808 sonzai 2023 Drama 106 Japan
Hamaguchi Ryuji
shinai
Kosaka
Kosaka,
Ay...

Adonyi-
df.iloc: While df.loc uses labels for indexing, df.iloc allows for integer-based indexing. You use
Walsh
df.iloc to access rows and columns by their integer positions, which
Magyarázat makes it useful when you
Hungary, need
Gáspár,
41366 229832 2023 Drama 151 Gábor Reisz
to access data by its positionmindenre
in the DataFrame. Slovakia István
Znamenák,
András R...
df.head(5)
Martin
Loeb,
filmtv_id title year
Mes petites
genre duration country directorsJean actors avg
Jacqueline
41390 232203 1974 Drama 123 France
amoureuses Eustache Dufranne,
Bugs
Jacques
Bunny's
David Roma...
Third
United Detiege, Art
0
3649 rows × 19 2columns
Movie: 1982 Animation 76 NaN
States Davis, Bill
1001
Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni
Simona
1 3 tra una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a United Don
2 17 1976 Romantic 91 Meillon,
Wild Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 Diner 1982 Comedy 95
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
4 20 1942 Comedy 85 Italy Peppino De
questi Pratelli
Filippo,
quattrini?
Clelia...

# Selecting a single row from the DataFrame


single_row = df.iloc[0]
single_row

filmtv_id 2
title Bugs Bunny's Third Movie: 1001 Rabbit Tales
year 1982
genre Animation
duration 76
country United States
directors David Detiege, Art Davis, Bill Perez
actors NaN
avg_vote 7.7
critics_vote 8.0
public_vote 7.0
total_votes 22
description With two protruding front teeth, a slightly sl...
notes These are many small independent stories, whic...
humor 3
rhythm 3
effort 0
tension 0
erotism 0
Name: 0, dtype: object

# Selecting a specific row and columns by integer indices


specific_data = df.iloc[10, [1, 2, 3]] # row at index 10 and columns at indices 1, 2, and 3
specific_data

title A Ghentar si muore facile


year 1968
genre Adventure
Name: 10, dtype: object

# Slicing to get multiple rows and columns


multi_slice = df.iloc[10:15, 0:4] # Rows 10 to 14 and columns 0 to 3
multi_slice

filmtv_id title year genre


10 30 A Ghentar si muore facile 1968 Adventure

11 32 Sleeping with the Enemy 1990 Drama

12 34 In Bed With Madonna 1990 Documentary

13 36 Bowery at Midnight 1942 Horror

14 37 A mezzanotte va la ronda del piacere 1975 Comedy

df.at: df.at is designed to access a single value for a row/column label pair. It is very similar to
df.loc for accessing scalar values but is optimized for faster access when you only need to get or
set a single value in a DataFrame.

# Access a specific single value using row label and column name
title_of_first_movie = df.at[0, 'title']
title_of_first_movie

'Bugs Bunny's Third Movie: 1001 Rabbit Tales'


Filtering Based on Criteria: Filtering data based on specific criteria is a common operation in data
analysis. Pandas provides several methods to perform these operations, often using boolean
indexing.

# Filter movies released after 2010


recent_movies = df[df['year'] > 2010]
recent_movies
filmtv_id title year genre duration country directors

B
Sea
United Terrence
22817 39955 The Tree of Life 2011 Drama 138
States Malick
C
T

Cag
Season of the United Dominic
23725 41448 2011 Adventure 95
Witch States Sena
P
St

Wasi
United Gus Van S
24186 42398 Restless 2011 Drama 95
States Sant Fi

A
Giulio
24426 42847 Qualunquemente 2011 Grotesque 96 Italy
Manfredonia

Ben
Una sconfinata
24427 42848 2011 Drama 98 Italy Pupi Avati Fra
giovinezza
Neri

... ... ... ... ... ... ... ...

Ju
Canada, Roa
Gold Digger
41394 232817 2021 Thriller 87 United Robin Hays
Killer
States Bra

Addio al nubilato Francesco


41395 232893 2023 Comedy 90 Italy
2 Apolloni

Katia

Patrik M
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund

A
Jeo
South Chung-Hyun seo,
41397 232919 Ballelina 2023 Thriller 92
Korea Lee rim
# Movies with a high public vote and specific genre
highly_rated_thrillers = df[(df['public_vote'] >= 8) & (df['genre'] == 'Thriller')]
highly_rated_thrillers

Invitación a un St
41398 232920 2023 Thriller 92 Mexico J.M Cravioto
Asesinato

Ca

13100 rows × 19 columns


filmtv_id title year genre duration country directors actors av
Dick
Powell,
Johnny United Robert Evelyn
21 54 1947 Thriller 95
O'Clock States Rossen Keyes, Lee
J. Cobb,
Ellen ...

Patty Duke,
Rosemary
You'll
United Lamont Murphy,
27 67 Like My 1973 Thriller 94
States Johnson Richard
Mother
Thomas,
S...

Michael
Redgrave,
Time
Great Joseph Ann Todd,
140 236 Without 1956 Thriller 88
Britain Losey Peter
Pity
Cushing,
Joa...

Farley
Granger,
Strangers Robert
United Alfred
183 296 on a 1951 Thriller 96 Walker,
States Hitchcock
Train Ruth
Roman,
Leo...

Ingrid
Bergman,
United George Charles
302 478 Gaslight 1944 Thriller 109
States Cukor Boyer,
Joseph
Cotten, ...

... ... ... ... ... ... ... ... ...

Satoshi
Tsumabuki,
Aru Kei Sakura
40950 216918 2022 Thriller 121 Japan
otoko Ishikawa Andô,
Masataka
Kubot...

The Kim Min-


South Jin-young
41118 220183 Other 2022 Thriller 114 Jae, Hyo-ju
Korea Kim
Child Park

Sandra
Hüller,
Anatomie Samuel
Justine
41200 221403 d'une 2023 Thriller 151 France Theis,
Triet
chute Swann
Arlaud
Arlaud,
Jeh...

# Movies from a specific country Ka-Tung


us_movies = df[df['country'] == 'United States'] Lam,
us_movies Hong Charm
41218 221890 Ming On 2022 Thriller 109 Soi Cheang
Kong Man Chan,
Wing-Sze
Ng, Lok ...

Hayley
Mills,
Hywel
Twisted Great Roy
41246 223251 1968 Thriller 112 Bennett,
Nerve Britain Boulting
Billie
Whitelaw,
...

327 rows × 19 columns


filmtv_id title year genre duration country directors

Bugs Bunny's
David Detiege,
Third Movie: United
0 2 1982 Animation 76 Art Davis, Bill
1001 Rabbit States
Perez
Tales

Ride a Wild United C


2 17 1976 Romantic 91 Don Chaffey
Pony States M
Gri

Rou
United
3 18 Diner 1982 Comedy 95 Barry Levinson G
States

Don

United John
7 23 Dead-Bang 1989 Crime 109
States Frankenheimer

C
At Close United Wa
9 26 1986 Drama 115 James Foley
Range States P
P

... ... ... ... ... ... ... ...

United Anthony
41377 231044 Shelter 2023 Thriller 91
States Nardolillo

To End All
War:
United Christopher Opp
41382 231556 Oppenheimer 2023 Documentary 87
States Cassel Kai
& the Atomic
Bomb

Hostage United Tay


41384 232066 2021 Horror 85 David Benullo
House States C

Ma
Fear the United
41385 232101 2023 Horror 92 Neil LaBute
Night States Ph
J

Zoé
United Michael
41391 232755 Organ Trail 2023 Western 112
States Patrick Jann

keyboard_arrow_down Updating Rows and Columns


Z

16490 rows × 19 columns

df.drop: The .drop() method in pandas is used to remove rows or columns from a DataFrame. Its
primary purpose is to drop specified labels from rows or columns.

Parameters:

labels: The row or column labels to drop.

axis: Specifies whether the labels refer to rows (axis=0) or columns (axis=1). By default, it's 0
(rows).

index or columns: An alternative way to specify the labels to drop, instead of using the labels
parameter. It is equivalent to specifying axis=0 (for index) or axis=1 (for columns).

inplace: If True, the operation is done in place, meaning it modifies the DataFrame directly and
returns None. If False or not specified, it returns a new DataFrame with the specified labels
dropped.

df.drop(labels='title',axis=1)
filmtv_id year genre duration country directors actors avg_vote

David
United Detiege, Art
0 2 1982 Animation 76 NaN 7.7
States Davis, Bill
Perez

Kim Rossi
Stuart,
Simona
1 3 1991 Drama 98 Italy Luigi Perelli 6.5
Cavallari,
Ennio
Fant...

Michael
Craig, John
United Don
2 17 1976 Romantic 91 Meillon, 5.7
States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 1982 Comedy 95 7.0
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
Filippo,
Esodo
4 20 1942 Comedy 85 Italy Peppino De 5.9
Pratelli
Filippo,
Clelia...

... ... ... ... ... ... ... ... ...

Julie Benz,
Roan
Canada,
Curtis,
41394 232817 2021 Thriller 87 United Robin Hays 4.0
Georgia
States
Bradner, Eli
...

Laura
Chiatti,
Francesco Chiara
41395 232893 2023 Comedy 90 Italy 2.7
Apolloni Francini,
Antonia
Liskov...

Katia
Winter, Eva
Patrik Melander,
41396 232915 2023 Horror 100 Sweden 6.0
Eklund Lola
Zackow,
Adam ...
Jeon Jong-
South Chung- seo, Park
41397 232919 2023 Thriller 92 5.8
Korea Hyun Lee Yu-rim, Ji-
df
hun Kim

Maribel
Verdú,
J.M Stephanie
41398 232920 2023 Thriller 92 Mexico 6.0
Cravioto Cayo,
Manolo
Cardona,...

41399 rows × 18 columns


filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1982 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung-
seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee
Yu-rim, J
Direct Assignment: Directly assign a value to a specific column or even a cell in a DataFrame. hun Kim

df.at[0, 'year'] = 1983 # Changes the year of the first movie to 1983 Marib
df.head(5) Verd
Invitación a
J.M Stephan
41398 232920 un 2023 Thriller 92 Mexico
Cravioto Cay
filmtv_id title year
Asesinato genre duration country directors actors Mano
avg
Cardona,
Bugs
Bunny's
41399 rows × 19 columns David
Third
United Detiege, Art
0 2 Movie: 1983 Animation 76 NaN
States Davis, Bill
1001
Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni
Simona
1 3 tra una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a United Don
2 17 1976 Romantic 91 Meillon,
Wild Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 Diner 1982 Comedy 95
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
4 20 1942 Comedy 85 Italy Peppino De
questi Pratelli
Filippo,
quattrini?
Clelia...

df['new_column'] = 'default value' # Adds a new column with all entries set to 'default va
df
filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1983 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
df.drop(axis=1,labels='new_column',inplace=True)
hun Kim

df.head(5) Marib
Verd
Invitación a
J.M Stephan
filmtv_id
41398 232920 title year un genre Thriller
2023 duration country
92 directors
Mexico actors avg
Cravioto Cay
Asesinato
Bugs Mano
Bunny's Cardona,
David
Third
41399 rows × 20 columns United Detiege, Art
0 2 Movie: 1983 Animation 76 NaN
States Davis, Bill
1001
Perez
Rabbit
Tales

Kim Rossi
Stuart,
18 anni
Simona
1 3 tra una 1991 Drama 98 Italy Luigi Perelli
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a United Don
2 17 1976 Romantic 91 Meillon,
Wild Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
3 18 Diner 1982 Comedy 95
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
4 20 1942 Comedy 85 Italy Peppino De
questi Pratelli
Filippo,
quattrini?
Clelia...

Using loc for Conditional Updates: loc can be used to update rows and columns based on a
condition.

df.loc[df['year'] < 2000, 'classic'] = True # Marks movies before 2000 as classic
df
filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1983 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
df.loc[df['avg_vote'] > 6, ['top_rated', 'must_watch']] = [True, True] # Modifying multiple
hun Kim

df Marib
Verd
Invitación a
J.M Stephan
41398 232920 un 2023 Thriller 92 Mexico
Cravioto Cay
Asesinato
Mano
Cardona,

41399 rows × 20 columns


filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1983 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
Using apply Function: The apply function allows you to apply a function along an axis of the hun Kim
DataFrame.
Marib
Verd
Invitación a
df['length_category'] = df['duration'].apply(lambda x: 'Long' if x > 120 else 'Short')
J.M Stephan
df 41398 232920 un 2023 Thriller 92 Mexico
Cravioto Cay
Asesinato
Mano
Cardona,

41399 rows × 22 columns


filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1983 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam

Jeon Jong
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
# Create a DataFrame with multiple Series hun Kim
data = {
'A': [1, 2, 3], Marib
'B': [4, 5, 6], Verd
'C': [7, 8, 9] Invitación a
J.M Stephan
} 41398 232920 un 2023 Thriller 92 Mexico
Cravioto Cay
Asesinato
num_data = pd.DataFrame(data) Mano
Cardona,

num_data
41399 rows × 23 columns

A B C
0 1 4 7

1 2 5 8

2 3 6 9

# Define a function to sum two Series


def sum_series(x, y):
return x + y

# Apply the function on multiple Series using apply()


result = num_data.apply(lambda row: sum_series(row['A'], row['B']), axis=1)

# Print the result


print(result)

0 5
1 7
2 9
dtype: int64

Updating Using map or replace: You can update a column based on a mapping dictionary or
replace values.

df['genre'].map({'Drama': 'Drama Film', 'Comedy': 'Comedy Film'}) # Mapping existing values

0 NaN
1 Drama Film
2 NaN
3 Comedy Film
4 Comedy Film
...
41394 NaN
41395 Comedy Film
41396 NaN
41397 NaN
41398 NaN
Name: genre, Length: 41399, dtype: object
df['country'].replace('USA', 'United States', inplace=True) # Replacing specific values
df
filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1982 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
Adding New Columns Based on Calculations: You can create new columns based on calculations
hun Kim
from existing columns.
Marib
Verd
Invitación
df['title_year'] = df['title'] + "a (" + df['year'].astype(str) + ")" # Creating a new colum
J.M Stephan
df 41398 232920 un 2023 Thriller 92 Mexico
Cravioto Cay
Asesinato
Mano
Cardona,

41399 rows × 19 columns


filmtv_id title year genre duration country directors actor
Bugs
David
Bunny's
United Detiege, Art
0 2 Third Movie: 1982 Animation 76 Na
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Ros
Stuar
18 anni tra
Simon
1 3 una 1991 Drama 98 Italy Luigi Perelli
Cavalla
settimana
Enn
Fant

Micha
Craig, Joh
Ride a Wild United Don
2 17 1976 Romantic 91 Meillo
Pony States Chaffey
Eva Griffit
Gra

Micke
Rourk
United Barry Stev
3 18 Diner 1982 Comedy 95
States Levinson Guttenber
Elle
Barkin,

Eduardo D
A che
Filipp
servono Esodo
4 20 1942 Comedy 85 Italy Peppino D
questi Pratelli
Filipp
quattrini?
Clelia

... ... ... ... ... ... ... ...

Julie Ben
Roa
Canada,
Gold Digger Curti
41394 232817 2021 Thriller 87 United Robin Hays
Killer Georg
States
Bradner, E

Laur
Chiat
Addio al Francesco Chiar
41395 232893 2023 Comedy 90 Italy
nubilato 2 Apolloni Francin
Anton
Liskov

Kat
Winter, Ev
Patrik Melande
41396 232915 Konferensen 2023 Horror 100 Sweden
Eklund Lo
Zackow
Adam
Jeon Jong
South Chung- seo, Par
41397 232919 Ballelina 2023 Thriller 92
Korea Hyun Lee Yu-rim, J
Using assign to Create Columns: assign helps you add new columns to a DataFrame in a hun Kim
functional style.
Marib
Verd
df = df.assign( Invitación a
J.M Stephan
41398 232920
is_older=lambda x: x['year'] un 2023
< 2000, Thriller 92 Mexico
Cravioto Cay
duration_hours=lambda x: x['duration'] / 60
Asesinato
Mano
) # Adding multiple new columns
Cardona,

41399 rows × 20 columns


df
title year genre duration country directors actors avg_vot
Bugs
David
Bunny's
United Detiege, Art
2 Third Movie: 1982 Animation 76 NaN 7.
States Davis, Bill
1001 Rabbit
Perez
Tales

Kim Rossi
Stuart,
18 anni tra
Simona
3 una 1991 Drama 98 Italy Luigi Perelli 6.
Cavallari,
settimana
Ennio
Fant...

Michael
Craig, John
Ride a Wild United Don
17 1976 Romantic 91 Meillon, 5.
Pony States Chaffey
Eva Griffith,
Gra...

Mickey
Rourke,
United Barry Steve
18 Diner 1982 Comedy 95 7.
States Levinson Guttenberg,
Ellen
Barkin,...

Eduardo De
A che
Filippo,
servono Esodo
20 1942 Comedy 85 Italy Peppino De 5.
questi Pratelli
Filippo,
quattrini?
Clelia...

... ... ... ... ... ... ... ...

Julie Benz,
Roan
Canada,
Gold Digger Curtis,
232817 2021 Thriller 87 United Robin Hays 4.
Killer Georgia
States
Bradner, Eli
...

Laura
Chiatti,
Addio al Francesco Chiara
232893 2023 Comedy 90 Italy 2.
nubilato 2 Apolloni Francini,
Antonia
Liskov...

Katia
Winter, Eva
Patrik Melander,
232915 Konferensen 2023 Horror 100 Sweden 6.
Eklund Lola
Zackow,
Adam ...
Jeon Jong-
South Chung- seo, Park
232919 Ballelina 2023 Thriller 92 5.

keyboard_arrow_down Changing the name of Index


Korea Hyun Lee Yu-rim, Ji-
hun Kim

Maribel
Pandas allows you to rename Verdú, the
the index of a DataFrame or Series, which can help in making
Invitación a
J.M Stephanie
232920
index more informative orun aligning
2023 it with
Thriller 92 Mexico
new data requirements. 6.
Cravioto Cayo,
Asesinato
Manolo
Cardona,...
Renaming the Index of a DataFrame:
41399 rows × 21 columns

df.index.names = ['movie_id'] # Renames the index to 'movie_id'

df

title year genre duration country directors actors avg_v

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