Dspracticalexternak 23 Aug
Dspracticalexternak 23 Aug
ipynb - Colab
upper_text = text.upper()
lower_text = text.lower()
title_text = text.title()
# replacing text
new_text= text.replace("mishra","sharma",1)
# regular expression
import re
new_text=re.sub(r'\d','#',text)
https://colab.research.google.com/drive/1cX6AODL4N5irOvig7eHabALQMtQhp9ys#scrollTo=nctpcKvWm3ov&printMode=true 1/1
8/23/24, 11:05 AM Untitled1.ipynb - Colab
Choose Files No file chosen Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to
enable.
Saving titanic.csv.csv to titanic.csv.csv
import pandas as pd
titanic_data = pd.read_csv('titanic.csv.csv')
print(titanic_data.head())
print(titanic_data.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 PassengerId 891 non-null int64
1 Survived 891 non-null int64
2 Pclass 891 non-null int64
3 Name 891 non-null object
4 Sex 891 non-null object
5 Age 714 non-null float64
6 SibSp 891 non-null int64
7 Parch 891 non-null int64
8 Ticket 891 non-null object
9 Fare 891 non-null float64
10 Cabin 204 non-null object
11 Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.7+ KB
None
print(titanic_data.describe())
Parch Fare
count 891.000000 891.000000
mean 0.381594 32.204208
std 0.806057 49.693429
min 0.000000 0.000000
25% 0.000000 7.910400
50% 0.000000 14.454200
75% 0.000000 31.000000
max 6.000000 512.329200
print(titanic_data.isnull().sum())
PassengerId 0
Survived 0
Pclass 0
Name 0
Sex 0
Age 177
SibSp 0
Parch 0
Ticket 0
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 1/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
Fare 0
Cabin 687
Embarked 2
dtype: int64
titanic_data['Age'].fillna(titanic_data['Age'].median(), inplace=True)
titanic_data.drop(columns=['Cabin'], inplace=True)
titanic_data['Pclass'] = titanic_data['Pclass'].astype('category')
plt.figure(figsize=(8,6 ))
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 2/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
plt.xlabel('Sex (1=Male, 0=Female)')
plt.ylabel('Survival Rate')
plt.show()
plt.figure(figsize=(8, 6))
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 3/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
plt.xlabel('Passenger Class')
plt.ylabel('Survival Rate')
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 4/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
plt.show()
plt.figure(figsize=(8, 6))
titanic_data['Age'].hist(bins=30)
<Axes: >
plt.title('Age Distribution')
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 5/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
plt.xlabel('Age')
Text(0.5, 0, 'Age')
plt.ylabel('Frequency')
plt.show()
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 6/7
8/23/24, 11:05 AM Untitled1.ipynb - Colab
plt.figure(figsize=(8, 6))
sns.boxplot(x=titanic_data['Age'])
<Axes: xlabel='Age'>
plt.xlabel('Age')
Text(0.5, 0, 'Age')
https://colab.research.google.com/drive/1u2xMNqmQm2rZbExm2iUura81YOqhogp2#scrollTo=Gt8MucUExK8k&printMode=true 7/7