Pandas - Colab
Pandas - Colab
import pandas as pd
data=pd.Series([12,20,30,40,50,60,70])
data=pd.Series([12,20,30,40,50,60,70], index=('a','b','c','d','e','f','g'))
data.values
data.index
data_Series={
'Cloumn1':pd.Series(data=[100,200,300,400,500,600,700],dtype='int16'),
'Cloumn2':pd.Series(data=[10,20,30,40,50,60,70],dtype='int16')
pd.DataFrame(data_Series)
Cloumn1 Cloumn2
0 100 10
1 200 20
2 300 30
3 400 40
4 500 50
5 600 60
6 700 70
data={
'Day':pd.Series(data=['D1','D2','D3','D4','D5','D6','D7','D8','D9','D10','D11','D12','D13','D14']),
'Outlook':pd.Series(data=['Sunny','Sunny','Overcast','Rain','Rain','Rain','Overcast','Sunny','Sunny','Rain','Sunny','Overcast','Overcas
'Temperature':pd.Series(data=['Hot','Hot','Hot','mild','cool','cool','cool','mild','cool','mild','mild','mild','Hot','mild']),
'Humidity':pd.Series(data=['high','high','high','high','normal','normal','normal','high','normal','normal','normal','high','normal','hig
'wind':pd.Series(data=['weak','strong','weak','weak','weak','strong','strong','weak','weak','weak','strong','strong','weak','strong']),
'play tennis':pd.Series(data=['no','no','yes','yes','yes','no','yes','no','yes','yes','yes','yes','yes','no'])}
pd.DataFrame(data)
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 1/7
4/5/25, 11:16 PM pandas - Colab
movies_df=pd.read_csv("https://raw.githubusercontent.com/ammishra08/MachineLearning/master/Datasets/movies.csv",sep=',')
display(movies_df)
The Weinstein
0 Zack and Miri Make a Porno Romance 70 1.747542 64 $41.94 2008
Company
The Weinstein
1 Youth in Revolt Comedy 52 1.090000 68 $19.62 2010
Company
movies_df.head()
The Weinstein
0 Zack and Miri Make a Porno Romance 70 1.747542 64 $41.94 2008
Company
The Weinstein
1 Youth in Revolt Comedy 52 1.090000 68 $19.62 2010
Company
movies_df.tail()
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 2/7
4/5/25, 11:16 PM pandas - Colab
Film Genre Lead Studio Audience score % Profitability Rotten Tomatoes % Worldwide Gross Year
movies_df.shape
(77, 8)
movies_df.columns
len(movies_df.columns)
print(movies_df.shape[0])
77
print(movies_df.shape[1])
movies_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 77 entries, 0 to 76
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Film 77 non-null object
1 Genre 77 non-null object
2 Lead Studio 77 non-null object
3 Audience score % 77 non-null int64
4 Profitability 77 non-null float64
5 Rotten Tomatoes % 77 non-null int64
6 Worldwide Gross 77 non-null object
7 Year 77 non-null int64
dtypes: float64(1), int64(3), object(4)
memory usage: 4.9+ KB
movies_df['Profitability'].sort_values()
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 3/7
4/5/25, 11:16 PM pandas - Colab
Profitability
3 0.000000
33 0.000000
57 0.000000
8 0.005000
42 0.252895
... ...
12 10.180027
7 11.089742
14 14.196400
60 22.913136
68 66.934000
77 rows × 1 columns
dtype: float64
movies_df['Profitability'].sort_values(ascending=False)
Profitability
68 66.934000
60 22.913136
14 14.196400
7 11.089742
12 10.180027
... ...
42 0.252895
8 0.005000
3 0.000000
33 0.000000
57 0.000000
77 rows × 1 columns
dtype: float64
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 4/7
4/5/25, 11:16 PM pandas - Colab
The Weinstein
39 My Week with Marilyn Drama 84 0.825800 83 $8.26 2011
Company
movies_df.iloc[10:25, :]
Film Genre Lead Studio Audience score % Profitability Rotten Tomatoes % Worldwide Gross Year
10 Tyler Perry's Why Did I get Married Romance Independent 47 3.724192 46 $55.86 2007
14 The Twilight Saga: New Moon Drama Summit 78 14.196400 27 $709.82 2009
20 The Curious Case of Benjamin Button Fantasy Warner Bros. 81 1.783944 73 $285.43 2008
movies_df.iloc[10:25, 2:7]
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 5/7
4/5/25, 11:16 PM pandas - Colab
movies_df.iloc[10:25, -1]
Year
10 2007
11 2011
12 2008
13 2009
14 2009
15 2009
16 2009
17 2009
18 2007
19 2008
20 2008
21 2010
22 2010
23 2011
24 2010
dtype: int64
movies_df.iloc[10:25, -2:]
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 6/7
4/5/25, 11:16 PM pandas - Colab
10 $55.86 2007
11 $702.17 2011
12 $376.66 2008
13 $205.30 2009
14 $709.82 2009
15 $101.33 2009
16 $314.70 2009
movies_df.iloc[10:30:2, 0:8:2]
17 $32.40 2009
10
19 Tyler Perry's Why 2008
$43.31 Did I get Married Independent 3.724192 $55.86
12
20 $285.43 2008 Twilight Summit 10.180027 $376.66
14
21 The$77.09
Twilight Saga:
2010 New Moon Summit 14.196400 $709.82
16
22 $355.01 The Proposal
2010 Disney 7.867500 $314.70
18
23 $60.18The Heartbreak Kid
2011 Paramount 2.129444 $127.77
20
24 The Curious$48.81
Case of 2010
Benjamin Button Warner Bros. 1.783944 $285.43
22 Tangled Disney 1.365692 $355.01
movies_new=movies_df.set_index("Film")
https://colab.research.google.com/drive/1nlTM-iwOFyzFMn8yY4olBw_bueZSx8bi#scrollTo=F02e0wqP59CS&printMode=true 7/7