Real-World Data Analysis with Python & Jupyter Book 2

Learn how to use Python and Jupyter Notebook


Learn how to use Python and Jupyter Notebook to transform raw datasets into clear insights and interactive charts. A step-by-step beginner's guide to data cleaning, exploration, and visualization


python -m jupyterlab

%pip install plotly


import plotly.express as px

import plotly.graph_objects as go

=========

%pip install chart-studio

========

import chart_studio.plotly as py

import plotly.graph_objs as go

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

=======

df.groupby('month')['hour'].count()

========


import plotly.express as px

=====

trace1=go.Bar(

    x=df.groupby('month') ['hour'].count().index, 

    y=df.groupby('month') ['hour'].count(),

    name='Priority'

)

=======

iplot([trace1])

=======


sns.distplot(df['day'])


======

plt.figure(figsize=(10,8))

plt.hist(df['day'], bins=30)

plt.xlabel('date of the month')

plt.ylabel('Total Journeys')

plt.title('Journeys by month day')

=======


======

sns.distplot(df['day'])

======


plt.figure(figsize=(10,8))
plt.hist(df['day'], bins=30, rwidth=0.8,range=(0.5,30.5))
plt.xlabel('date of the month')
plt.ylabel('Total Journeys')
plt.title('Journeys by month day')

=======


====
ax=sns.pointplot(x='hour', y='Lat', data=df, hue="weekday") 
ax.set_title('hoursoffday vs latitude of passenger')

or 2ed

ax = sns.pointplot(x='hour', y='Lat', data=df.reset_index(drop=True), hue='weekday')
ax.set_title('hoursoffday vs latitude of passenger')



======
df.head()


=====
df.groupby (['Base', 'month']) ['Date/Time'].count()

=======

base=df.groupby(['Base', 'month']) ['Date/Time'].count().reset_index()
base



====
plt.figure(figsize=(10,6))
sns.lineplot(x='month', y='Date/Time', hue='Base', data=base)


====
def count_rows(rows):
    return len(rows)




========
df.groupby(['weekday', 'hour']).apply(count_rows)

=======
by_cross=df.groupby (['weekday', 'hour']).apply(count_rows)
by_cross


========
pivot=by_cross.unstack()
pivot



=======

sns.heatmap(pivot)



=====

plt.figure(figsize=(10,6))
sns.heatmap(pivot)



====

def heatmap(col1,col2):
    by_cross=df.groupby ([col1,col2]).apply(count_rows)
    pivot=by_cross.unstack()
    plt.figure(figsize=(10,6))
    return sns.heatmap (pivot)





========

heatmap('day', 'hour')

========

df.head()



======
plt.plot(df['Lon'], df['Lat'], 'r+')





=====
plt.figure(figsize=(12,6))
plt.plot(df['Lon'], df['Lat'], 'r+',ms=0.5)
plt.xlim(-74.2,-73.7)
plt.ylim(40.6,41)



=======
df_out=df[df['weekday']=='Sunday']



=======

df_out.shape

=====
df_out.head()

=====
df_out.groupby(['Lat', 'Lon']) ['weekday'].count().reset_index()



=======
rush=df_out.groupby(['Lat', 'Lon']) ['weekday'].count().reset_index()

========
rush.columns=['Lat', 'Lon', 'no of trips']
======
rush



======
%pip install folium

======
from folium.plugins import HeatMap

=======

import folium

=====
folium.Map()




=====

basemap=folium.Map()
==========

HeatMap(rush, zoom=20, radius=15).add_to(basemap)
basemap


=========

import folium
from folium.plugins import HeatMap

======

def plot(df,day):
    basemap=folium.Map()
    df_out=df [df['weekday']==day]
    HeatMap(df_out.groupby(['Lat', 'Lon']) ['weekday'].count().reset_index(),zoom=20, radius=15).add_to(basemap)
    return basemap

======

plot(df,'Saturday')




===12===

uber_15=pd.read_csv(r'E:\Data Analysis work\Datasets\uber-raw-data-janjune-15.csv')




=====
uber_15.head()

=====
uber_15.dtypes

=====
uber_15['Pickup_date']=pd.to_datetime(uber_15['Pickup_date'], format='%Y-%m-%d %H:%M:%S')



=====

uber_15.dtypes
=====

uber_15['weekday']=uber_15['Pickup_date'].dt.day_name()
uber_15['day']=uber_15['Pickup_date'].dt.day
uber_15['minute']=uber_15['Pickup_date'].dt.minute
uber_15['month']=uber_15['Pickup_date'].dt.month
uber_15['hour']=uber_15['Pickup_date'].dt.hour

=======
uber_15.head()



======
px.bar(x=uber_15['month'].value_counts().index,
        y=uber_15['month'].value_counts())



========

plt.figure(figsize=(12,6))
sns.countplot(uber_15['hour'])

========

uber_15.groupby(['weekday', 'hour']) ['Pickup_date'].count()
=========

summary=uber_15.groupby(['weekday', 'hour']) ['Pickup_date'].count().reset_index()
summary.head()

========
summary.columns=['weekday', 'hour', 'counts']

=======

summary.head()

=======

plt.figure(figsize=(12,8))
sns.pointplot(x='hour', y='counts', hue='weekday', data=summary)

========





Learn Book One > Click Hear



Post a Comment