path
stringlengths 13
17
| screenshot_names
sequencelengths 1
873
| code
stringlengths 0
40.4k
| cell_type
stringclasses 1
value |
---|---|---|---|
73074336/cell_11 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.shape
df.columns
df.isnull().sum()
df.drop('company', inplace=True, axis=1)
df
df_Sort_by_adr = df.sort_values(by=['adr'], ascending=False)['name']
df_Sort_by_adr.dataFrame | code |
73074336/cell_7 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.shape
df.columns
df.tail() | code |
73074336/cell_8 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.shape
df.columns
df.isnull().sum() | code |
73074336/cell_3 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.info() | code |
73074336/cell_10 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.shape
df.columns
df.isnull().sum()
df.drop('company', inplace=True, axis=1)
df
df['country'].value_counts(sort=True)[:5] | code |
73074336/cell_5 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('/kaggle/input/hotel-booking/hotel_booking.csv')
df.shape
df.columns | code |
106195752/cell_21 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
print(c.dtype) | code |
106195752/cell_4 | [
"text_plain_output_1.png"
] | pip install numpy | code |
106195752/cell_23 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
print(e.dtype) | code |
106195752/cell_30 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
Y = np.ones((3, 4))
Z = np.full((3, 4), 5)
print(Z) | code |
106195752/cell_33 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
Y = np.ones((3, 4))
Z = np.full((3, 4), 5)
I = np.eye(5)
D = np.diag([1, 2, 3, 4])
N = np.arange(10)
M = np.arange(10, 30)
O = np.arange(10, 30, 3)
print(N)
print(M)
print(O) | code |
106195752/cell_20 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print('rank: ', b.ndim) | code |
106195752/cell_29 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
Y = np.ones((3, 4))
print(Y) | code |
106195752/cell_26 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
print(y) | code |
106195752/cell_19 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print(b.shape) | code |
106195752/cell_18 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print(b) | code |
106195752/cell_32 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
Y = np.ones((3, 4))
Z = np.full((3, 4), 5)
I = np.eye(5)
D = np.diag([1, 2, 3, 4])
print(D) | code |
106195752/cell_28 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
print(X) | code |
106195752/cell_15 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
print('rank: ', a.ndim) | code |
106195752/cell_16 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
print(a.shape) | code |
106195752/cell_17 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
print(a.dtype) | code |
106195752/cell_31 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
x = np.array([1, 2, 3, 4, 5])
np.save('my_array', x)
y = np.load('my_array.npy')
X = np.zeros((3, 4))
Y = np.ones((3, 4))
Z = np.full((3, 4), 5)
I = np.eye(5)
print(I) | code |
106195752/cell_24 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
e = np.array([1, 2.3, 5])
f = np.array([1, 2.3, 4], dtype=np.int64)
print(f.dtype) | code |
106195752/cell_14 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
print(a)
print(type(a)) | code |
106195752/cell_22 | [
"text_plain_output_1.png"
] | import numpy as np
import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
start = time.time()
np.mean(x)
a = np.array([1, 2, 3, 4, 5])
b = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
c = np.array(['Hello', 'World'])
d = np.array([1, 2, 3, 'Hello'])
print(d.dtype) | code |
106195752/cell_10 | [
"text_plain_output_1.png"
] | import numpy as np
import time
import time
import numpy as np
x = np.random.random(100000000)
start = time.time()
sum(x) / len(x)
print('using built-in python function: ', time.time() - start)
start = time.time()
np.mean(x)
print('using NumPy: ', time.time() - start) | code |
2022470/cell_21 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values | code |
2022470/cell_25 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.head(2) | code |
2022470/cell_34 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
sns.countplot('Sex', hue='Survived', data=df) | code |
2022470/cell_23 | [
"image_output_1.png"
] | import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
sns.countplot('Sex', hue='Survived', data=df)
plt.show() | code |
2022470/cell_33 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df | code |
2022470/cell_29 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r') | code |
2022470/cell_39 | [
"text_plain_output_1.png"
] | import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
fig = plt.gcf()
fig.set_size_inches(10, 8)
df['Survived'].mean() | code |
2022470/cell_26 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df['Age_band'].value_counts().to_frame().style.background_gradient(cmap='summer') | code |
2022470/cell_19 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.head() | code |
2022470/cell_32 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df.groupby(['Sex', 'Survived'])[['Survived']].count().plot(kind='bar') | code |
2022470/cell_35 | [
"application_vnd.jupyter.stderr_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Sex'].replace(['female', 'male'], [1, 0], inplace=True) | code |
2022470/cell_31 | [
"text_html_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r') | code |
2022470/cell_27 | [
"text_plain_output_1.png"
] | import pandas as pd
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum() | code |
2022470/cell_37 | [
"image_output_1.png"
] | import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)
df.columns.values
df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4
df.Age.isnull().sum()
pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
df['Title'] = None
for index, row in enumerate(df['Name']):
title = row.split(', ')[1].split('. ')[0]
if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
df.loc[index, 'Title'] = 'Mr'
elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
df.loc[index, 'Title'] = 'Mrs'
elif title in ['Master']:
df.loc[index, 'Title'] = 'Master'
elif title in ['Miss', 'Mlle']:
df.loc[index, 'Title'] = 'Ms'
else:
df.loc[index, 'Title'] = 'Other'
pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')
sns.heatmap(df.corr(), annot=True, cmap='RdYlGn', linewidths=0.2)
fig = plt.gcf()
fig.set_size_inches(10, 8)
plt.show() | code |
16139957/cell_9 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
rd['Longitude'].hist() | code |
16139957/cell_4 | [
"text_html_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_ | code |
16139957/cell_6 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()] | code |
16139957/cell_11 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
latitude = rd['Latitude']
longitude = rd['Longitude']
(latitude, longitude)
min_lat, max_lat = (min(latitude), max(latitude))
min_lng, max_lng = (min(longitude), max(longitude))
(min_lat, max_lat, min_lng, max_lng) | code |
16139957/cell_19 | [
"text_plain_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data
date_grid = np.zeros((max(data['Days']) + 1, max(data['Grid']) + 1), dtype='bool')
date_grid.shape
len(date_grid[date_grid == True]) / date_grid.size | code |
16139957/cell_1 | [
"text_plain_output_1.png"
] | import os
import numpy as np
import pandas as pd
import os
print(os.listdir('../input')) | code |
16139957/cell_7 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape | code |
16139957/cell_18 | [
"text_plain_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data
date_grid = np.zeros((max(data['Days']) + 1, max(data['Grid']) + 1), dtype='bool')
date_grid.shape
date_grid[data['Days'], data['Grid']] = True
len(date_grid[date_grid == True]) | code |
16139957/cell_8 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
rd['Latitude'].hist() | code |
16139957/cell_15 | [
"text_plain_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data
max(data['Grid']) | code |
16139957/cell_16 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data
(min(data['Days']), max(data['Days'])) | code |
16139957/cell_3 | [
"text_plain_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days | code |
16139957/cell_17 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data
date_grid = np.zeros((max(data['Days']) + 1, max(data['Grid']) + 1), dtype='bool')
date_grid.shape | code |
16139957/cell_14 | [
"application_vnd.jupyter.stderr_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)
def to_grid(lat, lng):
x = (lng - min_lng) // lng_step
y = (lat - min_lat) // lat_step
return x + GRID_X_DIM * y
data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data | code |
16139957/cell_10 | [
"text_plain_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]
rd.shape
latitude = rd['Latitude']
longitude = rd['Longitude']
(latitude, longitude) | code |
16139957/cell_12 | [
"text_plain_output_1.png"
] | GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step) | code |
16139957/cell_5 | [
"text_plain_output_1.png"
] | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()
first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days
days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_
min_days = min(days_)
max_days = max(days_)
(min_days, max_days) | code |
16123173/cell_6 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import calendar
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df['Weekday'] = df.Date.dt.weekday
df['Weekday'] = df['Weekday'].apply(lambda x: calendar.day_name[x])
weekdays_total = df.groupby('Weekday').size().plot.bar()
totals = []
for i in weekdays_total.patches:
totals.append(i.get_height())
total = sum(totals)
for i in weekdays_total.patches:
weekdays_total.text(i.get_x() + 0.0, i.get_height() - 0, i.get_height(), fontsize=12, color='black') | code |
16123173/cell_2 | [
"text_html_output_1.png",
"application_vnd.jupyter.stderr_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.head() | code |
16123173/cell_11 | [
"text_plain_output_1.png"
] | import calendar
import matplotlib.pyplot as plt
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df['Weekday'] = df.Date.dt.weekday
df['Weekday'] = df['Weekday'].apply(lambda x: calendar.day_name[x])
weekdays_total=df.groupby('Weekday').size().plot.bar()
totals = []
# find the values and append to list
for i in weekdays_total.patches:
totals.append(i.get_height())
# set individual bar lables using above list
total = sum(totals)
# set individual bar lables using above list
for i in weekdays_total.patches:
# get_x pulls left or right; get_height pushes up or down
weekdays_total.text(i.get_x()+.0, i.get_height()-0, \
i.get_height(), fontsize=12,
color='black')
grouped=df.groupby('Route').size().sort_values(ascending=False)
graph_grouped=grouped[:15].plot.bar(title='The most popular destinations weekly', figsize=(12,8))
# find the values and append to list
for i in graph_grouped.patches:
totals.append(i.get_height())
# set individual bar lables using above list
total = sum(totals)
# set individual bar lables using above list
for i in graph_grouped.patches:
# get_x pulls left or right; get_height pushes up or down
graph_grouped.text(i.get_x()+.0, i.get_height()-0, \
i.get_height(), fontsize=12,
color='black')
df['Time'] = df.Time.dt.hour
tf=df.loc[df.Weekday.isin(['Monday','Tuesday','Wednesday','Thursday','Friday'])]
workdays=tf.groupby(['Time','Weekday']).count()['Route'].unstack().plot(kind='line',linewidth=3.0, title='Other card distribution per hours',\
figsize=(18,10))
workdays
plt.xticks(np.arange(0,24,step=1))
kf = df.loc[df.Weekday.isin(['Saturday', 'Sunday'])]
weekends = kf.groupby(['Time', 'Weekday']).count()['Route'].unstack().plot(kind='line', linewidth=3.0, title='Other card distribution per hours', figsize=(16, 6))
weekends
plt.xticks(np.arange(0, 24, step=1)) | code |
16123173/cell_1 | [
"text_plain_output_1.png"
] | import numpy as np
import pandas as pd
import os
from datetime import datetime
import calendar
import matplotlib.pyplot as plt
import seaborn as sns
print(os.listdir('../input')) | code |
16123173/cell_7 | [
"text_plain_output_1.png",
"image_output_1.png"
] | import calendar
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df['Weekday'] = df.Date.dt.weekday
df['Weekday'] = df['Weekday'].apply(lambda x: calendar.day_name[x])
weekdays_total=df.groupby('Weekday').size().plot.bar()
totals = []
# find the values and append to list
for i in weekdays_total.patches:
totals.append(i.get_height())
# set individual bar lables using above list
total = sum(totals)
# set individual bar lables using above list
for i in weekdays_total.patches:
# get_x pulls left or right; get_height pushes up or down
weekdays_total.text(i.get_x()+.0, i.get_height()-0, \
i.get_height(), fontsize=12,
color='black')
grouped = df.groupby('Route').size().sort_values(ascending=False)
graph_grouped = grouped[:15].plot.bar(title='The most popular destinations weekly', figsize=(12, 8))
for i in graph_grouped.patches:
totals.append(i.get_height())
total = sum(totals)
for i in graph_grouped.patches:
graph_grouped.text(i.get_x() + 0.0, i.get_height() - 0, i.get_height(), fontsize=12, color='black') | code |
16123173/cell_3 | [
"image_output_1.png"
] | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df.info() | code |
16123173/cell_10 | [
"text_html_output_1.png"
] | import calendar
import matplotlib.pyplot as plt
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df['Weekday'] = df.Date.dt.weekday
df['Weekday'] = df['Weekday'].apply(lambda x: calendar.day_name[x])
weekdays_total=df.groupby('Weekday').size().plot.bar()
totals = []
# find the values and append to list
for i in weekdays_total.patches:
totals.append(i.get_height())
# set individual bar lables using above list
total = sum(totals)
# set individual bar lables using above list
for i in weekdays_total.patches:
# get_x pulls left or right; get_height pushes up or down
weekdays_total.text(i.get_x()+.0, i.get_height()-0, \
i.get_height(), fontsize=12,
color='black')
grouped=df.groupby('Route').size().sort_values(ascending=False)
graph_grouped=grouped[:15].plot.bar(title='The most popular destinations weekly', figsize=(12,8))
# find the values and append to list
for i in graph_grouped.patches:
totals.append(i.get_height())
# set individual bar lables using above list
total = sum(totals)
# set individual bar lables using above list
for i in graph_grouped.patches:
# get_x pulls left or right; get_height pushes up or down
graph_grouped.text(i.get_x()+.0, i.get_height()-0, \
i.get_height(), fontsize=12,
color='black')
df['Time'] = df.Time.dt.hour
tf = df.loc[df.Weekday.isin(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'])]
workdays = tf.groupby(['Time', 'Weekday']).count()['Route'].unstack().plot(kind='line', linewidth=3.0, title='Other card distribution per hours', figsize=(18, 10))
workdays
plt.xticks(np.arange(0, 24, step=1)) | code |
16123173/cell_5 | [
"image_output_1.png"
] | import calendar
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
df = pd.read_excel('../input/flight_schedule.xlsx')
df.Date = pd.to_datetime(df.Date)
df.Time = df.Time.astype(str)
df.Time = pd.to_datetime(df.Time)
df['Weekday'] = df.Date.dt.weekday
df['Weekday'] = df['Weekday'].apply(lambda x: calendar.day_name[x])
cats = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
df['Weekday'] = df['Weekday'].astype('category', categories=cats, ordered=True)
df | code |
34126468/cell_13 | [
"text_plain_output_1.png"
] | stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack | code |
34126468/cell_9 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana')
fruits.index('banana', 4)
fruits.reverse()
fruits
fruits.append('grape')
fruits | code |
34126468/cell_25 | [
"text_plain_output_1.png"
] | t = (12345, 54321, 'hello!')
t[0] | code |
34126468/cell_4 | [
"application_vnd.jupyter.stderr_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple') | code |
34126468/cell_6 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana') | code |
34126468/cell_40 | [
"text_plain_output_1.png"
] | a = set('abracadabra')
b = set('alacazam')
a | code |
34126468/cell_29 | [
"text_plain_output_1.png"
] | v = ([1, 2, 3], [3, 2, 1])
v | code |
34126468/cell_39 | [
"text_plain_output_1.png"
] | basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
'crabgrass' in basket | code |
34126468/cell_26 | [
"text_plain_output_1.png"
] | t = (12345, 54321, 'hello!')
t[0]
t | code |
34126468/cell_48 | [
"text_plain_output_1.png"
] | tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
tel
del tel['sape']
tel | code |
34126468/cell_11 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana')
fruits.index('banana', 4)
fruits.reverse()
fruits
fruits.append('grape')
fruits
fruits.sort()
fruits
fruits.pop() | code |
34126468/cell_7 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana')
fruits.index('banana', 4) | code |
34126468/cell_28 | [
"text_plain_output_1.png"
] | t = (12345, 54321, 'hello!')
t[0]
t[0] = 88888 | code |
34126468/cell_8 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana')
fruits.index('banana', 4)
fruits.reverse()
fruits | code |
34126468/cell_15 | [
"text_plain_output_1.png"
] | stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack
stack.pop()
stack | code |
34126468/cell_16 | [
"text_plain_output_1.png"
] | stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack
stack.pop()
stack.pop()
stack.pop()
stack | code |
34126468/cell_38 | [
"text_plain_output_1.png"
] | basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
'orange' in basket | code |
34126468/cell_47 | [
"text_plain_output_1.png"
] | tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
tel
tel['jack'] | code |
34126468/cell_35 | [
"text_plain_output_1.png"
] | t = (12345, 54321, 'hello!')
t[0]
x, y, z = t
print(x, y, z) | code |
34126468/cell_46 | [
"text_plain_output_1.png"
] | tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
tel | code |
34126468/cell_14 | [
"text_plain_output_1.png"
] | stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack
stack.pop() | code |
34126468/cell_10 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine')
fruits.index('banana')
fruits.index('banana', 4)
fruits.reverse()
fruits
fruits.append('grape')
fruits
fruits.sort()
fruits | code |
34126468/cell_27 | [
"text_plain_output_1.png"
] | t = (12345, 54321, 'hello!')
t[0]
u = (t, (1, 2, 3, 4, 5))
u | code |
34126468/cell_37 | [
"text_plain_output_1.png"
] | basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
print(basket) | code |
34126468/cell_5 | [
"text_plain_output_1.png"
] | fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
fruits.count('tangerine') | code |
106194155/cell_11 | [
"text_html_output_1.png"
] | data = port.copy()
data.head() | code |
106194155/cell_15 | [
"text_html_output_2.png"
] | import plotly.express as px
import plotly.express as px
data = port.copy()
data.Pstatus.value_counts()
import plotly.express as px
fig = px.funnel(data, x='sex', y='G3')
fig.show() | code |
106194155/cell_14 | [
"text_plain_output_1.png"
] | data = port.copy()
data.Pstatus.value_counts() | code |
106194155/cell_12 | [
"text_plain_output_1.png"
] | data = port.copy()
data.info() | code |
129007065/cell_2 | [
"text_plain_output_2.png",
"application_vnd.jupyter.stderr_output_1.png"
] | from gensim.models import KeyedVectors
from sklearn.neighbors import NearestNeighbors
import numpy as np
import numpy as np # linear algebra
import pandas as pd
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from sklearn.neighbors import NearestNeighbors
from gensim.models import KeyedVectors
import numpy as np
import ast
import pandas as pd
data_path = '/kaggle/input/2-recommended-reads-conversion-of-data-to-num/vectorizedData.csv'
data = pd.read_csv(data_path)
data = data.drop_duplicates(subset=['booktitle', 'authorname'], keep='first')
data['word2vec'] = data['word2vec'].apply(lambda x: x.strip('[]'))
data['word2vec'] = data['word2vec'].apply(lambda x: x.split())
data['word2vec'] = data['word2vec'].apply(lambda x: [float(y) for y in x])
model_path = '/kaggle/input/googlenewsvectors/GoogleNews-vectors-negative300.bin'
word_vectors = KeyedVectors.load_word2vec_format(model_path, binary=True)
user_description = 'a space adventure with friends'
user_vector = np.mean([word_vectors[word] for word in user_description.split() if word in word_vectors.key_to_index], axis=0)
nn_model = NearestNeighbors(n_neighbors=10, metric='cosine')
X = np.array(data['word2vec'].tolist())
nn_model.fit(X)
distances, indices = nn_model.kneighbors([user_vector])
recommended_books = data.iloc[indices[0]][['booktitle', 'authorname']].values.tolist()
print('Kullanıcının girdiği kitaba benzer kitaplar:')
for i, book in enumerate(recommended_books):
similarity = 1 - distances[0][i]
similarity_percent = round(similarity * 100, 2)
print(f'{book[0]} by {book[1]} ({similarity_percent}%)') | code |
129007065/cell_1 | [
"text_plain_output_1.png"
] | import os
import numpy as np
import pandas as pd
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename)) | code |
129007065/cell_3 | [
"image_output_1.png"
] | from gensim.models import KeyedVectors
from sklearn.neighbors import NearestNeighbors
import matplotlib.pyplot as plt
import numpy as np
import numpy as np # linear algebra
import pandas as pd
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from sklearn.neighbors import NearestNeighbors
from gensim.models import KeyedVectors
import numpy as np
import ast
import pandas as pd
data_path = '/kaggle/input/2-recommended-reads-conversion-of-data-to-num/vectorizedData.csv'
data = pd.read_csv(data_path)
data = data.drop_duplicates(subset=['booktitle', 'authorname'], keep='first')
data['word2vec'] = data['word2vec'].apply(lambda x: x.strip('[]'))
data['word2vec'] = data['word2vec'].apply(lambda x: x.split())
data['word2vec'] = data['word2vec'].apply(lambda x: [float(y) for y in x])
model_path = '/kaggle/input/googlenewsvectors/GoogleNews-vectors-negative300.bin'
word_vectors = KeyedVectors.load_word2vec_format(model_path, binary=True)
user_description = 'a space adventure with friends'
user_vector = np.mean([word_vectors[word] for word in user_description.split() if word in word_vectors.key_to_index], axis=0)
nn_model = NearestNeighbors(n_neighbors=10, metric='cosine')
X = np.array(data['word2vec'].tolist())
nn_model.fit(X)
distances, indices = nn_model.kneighbors([user_vector])
recommended_books = data.iloc[indices[0]][['booktitle', 'authorname']].values.tolist()
for i, book in enumerate(recommended_books):
similarity = 1 - distances[0][i]
similarity_percent = round(similarity * 100, 2)
import matplotlib.pyplot as plt
books = [book[0] for book in recommended_books]
similarity_percents = [round((1 - distance) * 100, 2) for distance in distances[0]]
fig, ax = plt.subplots(figsize=(8, 6))
ax.barh(books, similarity_percents, align='center', color='skyblue')
ax.set_xlabel('Benzerlik Oranı (%)')
ax.set_title('Kullanıcının Girdiği Kitaba Benzer Kitaplar')
plt.subplots_adjust(left=0.3)
for i, v in enumerate(similarity_percents):
ax.text(v + 2, i - 0.15, str(v), color='blue', fontweight='bold')
plt.gca().invert_yaxis()
plt.show() | code |
72111100/cell_13 | [
"text_html_output_1.png"
] | train = pd.read_csv('../input/car-price/train set.csv')
names = [x.split(' ')[0] for x in list(train['name'])]
train.insert(0, 'brand', names)
train = train.drop(['name', 'seller_type', 'owner', 'torque', 'fuel'], axis=1)
train['engine'] = [int(x.split(' ')[0]) for x in list(train['engine'])]
train['mileage'] = [float(x.split(' ')[0]) for x in list(train['mileage'])]
train['max_power'] = [float(x.split(' ')[0]) for x in list(train['max_power'])]
num_features = [x for x in train.columns if type(train[x][0]) is not str]
cat_features = [x for x in train.columns if x not in num_features]
import seaborn as sns, matplotlib.pyplot as plt
sns.barplot(y=train['brand'], x=train['selling_price'])
plt.show() | code |
72111100/cell_25 | [
"text_html_output_1.png"
] | from sklearn.linear_model import LinearRegression as LR, Perceptron
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR
train = pd.read_csv('../input/car-price/train set.csv')
names = [x.split(' ')[0] for x in list(train['name'])]
train.insert(0, 'brand', names)
train = train.drop(['name', 'seller_type', 'owner', 'torque', 'fuel'], axis=1)
train['engine'] = [int(x.split(' ')[0]) for x in list(train['engine'])]
train['mileage'] = [float(x.split(' ')[0]) for x in list(train['mileage'])]
train['max_power'] = [float(x.split(' ')[0]) for x in list(train['max_power'])]
num_features = [x for x in train.columns if type(train[x][0]) is not str]
cat_features = [x for x in train.columns if x not in num_features]
X_train = train.drop('selling_price', axis=1).values[0:6850]
y_train = train['selling_price'].values[0:6850]
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaled_X_train = scaler.fit_transform(X_train)
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.metrics import *
from math import sqrt
mcc = make_scorer(mean_absolute_error)
def evaluate_model(model):
model = model
import sklearn
scores = cross_val_score(model, scaled_X_train, y_train, scoring=mcc, cv=5, n_jobs=-1)
return scores.mean()
models = [KNR(), RNR(), LR(), RFR(n_estimators=300), Perceptron(), SVR(), MLPR()]
models_names = ['K_neighbors', 'radius_neighbors', 'linear_regression', 'random_forest_regressor', 'perceptron', 'SVR', 'MLP_Regression']
scores = list()
for clf, clf_name in zip(models, models_names):
k_mean = evaluate_model(clf)
scores.append(k_mean)
model = models[3]
print(model) | code |
72111100/cell_26 | [
"text_plain_output_1.png"
] | from sklearn.linear_model import LinearRegression as LR, Perceptron
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR
train = pd.read_csv('../input/car-price/train set.csv')
names = [x.split(' ')[0] for x in list(train['name'])]
train.insert(0, 'brand', names)
train = train.drop(['name', 'seller_type', 'owner', 'torque', 'fuel'], axis=1)
train['engine'] = [int(x.split(' ')[0]) for x in list(train['engine'])]
train['mileage'] = [float(x.split(' ')[0]) for x in list(train['mileage'])]
train['max_power'] = [float(x.split(' ')[0]) for x in list(train['max_power'])]
num_features = [x for x in train.columns if type(train[x][0]) is not str]
cat_features = [x for x in train.columns if x not in num_features]
X_train = train.drop('selling_price', axis=1).values[0:6850]
y_train = train['selling_price'].values[0:6850]
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaled_X_train = scaler.fit_transform(X_train)
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.metrics import *
from math import sqrt
mcc = make_scorer(mean_absolute_error)
def evaluate_model(model):
model = model
import sklearn
scores = cross_val_score(model, scaled_X_train, y_train, scoring=mcc, cv=5, n_jobs=-1)
return scores.mean()
models = [KNR(), RNR(), LR(), RFR(n_estimators=300), Perceptron(), SVR(), MLPR()]
models_names = ['K_neighbors', 'radius_neighbors', 'linear_regression', 'random_forest_regressor', 'perceptron', 'SVR', 'MLP_Regression']
scores = list()
for clf, clf_name in zip(models, models_names):
k_mean = evaluate_model(clf)
scores.append(k_mean)
model = models[3]
model.fit(scaled_X_train, y_train) | code |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.