<jupyter_start><jupyter_text>By Gender<jupyter_code>data["gender"].value_counts()
#bar plots by sex where 1 is male and 2 is female and 0 is not disclosed
ax = data['gender'].value_counts().plot(kind='barh')
xticks = [i for i in range(3)]
x_labels = ["Male","Female","Unkown"]
#ax.set_xticks(xticks)
ax.set_yticklabels(x_labels)<jupyter_output><empty_output><jupyter_text>Using interactivity<jupyter_code>from bokeh.plotting import figure, output_file 
from bokeh.io import show,output_notebook
from bokeh.palettes import Plasma
from bokeh.models import ColumnDataSource
from bokeh.transform import factor_cmap
from bokeh.models import FuncTickFormatter
y_range = [i for i in data["gender"].value_counts()]
print(y_range)
x_range = ["Male","Female","Unknown"]
output_notebook()
#output_file('bars.html')
source = ColumnDataSource(data=dict(gender=x_range, counts=y_range, color=Plasma[3]))
p = figure(x_range=x_range,y_range=(0,660000) ,plot_height=250, title="Gender Counts")
#p.vbar(x=x_range, top=y_range, width=0.9,color="firebrick")
p.vbar(x='gender', top='counts', width=0.9, color='color', legend="gender",source=source)
#p.xgrid.grid_line_color = None
p.legend.orientation = "horizontal"
p.legend.location = "top_right"
p.xaxis.axis_label = "Gender"
p.yaxis.axis_label = "Counts"

show(p)<jupyter_output><empty_output><jupyter_text>User type Bar plots<jupyter_code>data["usertype"].value_counts()<jupyter_output><empty_output><jupyter_text>Using same interactivity as above<jupyter_code>#(Customer = 24-hour pass or 3-day pass user; Subscriber = Annual Member)
y_range = [i for i in data["usertype"].value_counts()]
x_range = ["Subscriber","Customer"]
p = figure(x_range=x_range,y_range=(0,900000) ,plot_height=250, title="UserType Counts")
p.vbar(x=x_range, top=y_range, width=0.9)
#p.xgrid.grid_line_color = None
p.legend.orientation = "horizontal"
p.legend.location = "top_right"
p.xaxis.axis_label = "UserType"
p.yaxis.axis_label = "Counts"

show(p)<jupyter_output><empty_output><jupyter_text>Number of trips per day<jupyter_code>data["starttime"] = pd.to_datetime(data['starttime'])
data["stoptime"] = pd.to_datetime(data["stoptime"])
data["hour"] = data["starttime"].map(lambda x: x.hour)
ax = data['starttime'].map(lambda t: t.day).value_counts().sort_index().plot()
ax.set_ylabel("Number of trips")
ax.set_xlabel("Days")<jupyter_output><empty_output><jupyter_text>Number of trips a station could have<jupyter_code>ax = data['start station id'].value_counts().reset_index(drop=True).plot()
ax.set_xlabel("Station ID")
ax.set_ylabel("Count of trips of each station")<jupyter_output><empty_output><jupyter_text>We can see that a station can have as many as 10000 trips and close to 0 trips   Least active station id is<jupyter_code>data[data['start station id'] == data['start station id'].value_counts().index[-1]][['start station name', 'start station latitude', 'start station longitude']].head(1)<jupyter_output><empty_output><jupyter_text>Most Actve station id is<jupyter_code>data[data['start station id'] == data['start station id'].value_counts().index[0]][['start station name', 'start station latitude', 'start station longitude']].head(1)<jupyter_output><empty_output><jupyter_text>Number of bikes leaving a station id<jupyter_code>bikes = dict()
for bike_id in set(data['bikeid'].values):
    bikes.update({bike_id: len(data[data['bikeid'] == bike_id])})
bikes = pd.Series(bikes)
ax = bikes.sort_values(ascending=False).reset_index(drop=True).plot()
ax.set_ylabel("Station ID")
ax.set_xlabel("Count of bikes leaving station")<jupyter_output><empty_output><jupyter_text>Number of trips with a given end date (interactive graph)<jupyter_code>data_start = data.groupby("start_date").agg("count")["bikeid"]

@ipywidgets.interact( end = (1, 31, 1))
def make_plot(end=1):
   
    x_sc=bqplot.LinearScale(min=1,max=31)
    y_sc=bqplot.LinearScale(min=5000,max=60000)
    lines = pyplot.plot(data_start[1:end], scales = {'x': x_sc, 'y': y_sc})
    ax_x = bqplot.Axis(scale = x_sc,label = 'Days')
    ax_y = bqplot.Axis(scale = y_sc, label = 'Number of rides each day', orientation = 'vertical')
    
    #br_sel = bqplot.interacts.BrushSelector(x_scale=x_sc, y_scale=y_sc, marks=[lines], color='red')
    #db_scat_brush = HTML(value='[]')
    #def brush_callback(change):
    #    db_scat_brush.value = str(br_sel.selected)
    
    #br_sel.observe(brush_callback, names=['brushing'])
    
    panzoom = bqplot.interacts.PanZoom(scales={'x': [x_sc], 'y': [y_sc]})

    fig = Figure(marks = [lines], axes = [ax_x, ax_y],interaction=panzoom)
    #print(fig)
    display(fig)
    #display(VBox([db_scat_brush, fig]))

#make_plot()<jupyter_output><empty_output><jupyter_text>Using many selectors together for a more informed representation<jupyter_code>x_sc=bqplot.LinearScale(min=1,max=31)
y_sc=bqplot.LinearScale(min=5000,max=60000)
lines = pyplot.plot(data_start[1:31], scales = {'x': x_sc, 'y': y_sc})
ax_x = bqplot.Axis(scale = x_sc,label = 'Days')
ax_y = bqplot.Axis(scale = y_sc, label = 'Number of rides each day', orientation = 'vertical')

fig = Figure(marks = [lines], axes = [ax_x, ax_y])
multi_sel = bqplot.interacts.MultiSelector(scale=x_sc, marks=[lines])
br_intsel = bqplot.interacts.BrushIntervalSelector(scale=x_sc, marks=[lines])
index_sel = bqplot.interacts.IndexSelector(scale=x_sc, marks=[lines])
int_sel = bqplot.interacts.FastIntervalSelector(scale=x_sc, marks=[lines])

hd = bqplot.interacts.HandDraw(lines=lines)
pz = bqplot.interacts.PanZoom(scales={'x': [x_sc], 'y': [y_sc]})

deb = HTML()
deb.value = '[]'

def test_callback(change):
    deb.value = str(change.new)
    
multi_sel.observe(test_callback, names=['selected'])
br_intsel.observe(test_callback, names=['selected'])
index_sel.observe(test_callback, names=['selected'])
int_sel.observe(test_callback, names=['selected'])
from collections import OrderedDict
from traitlets import link

selection_interacts = ToggleButtons(options=OrderedDict([('HandDraw1', hd), ('PanZoom', pz), 
                                                       ('FastIntervalSelector', int_sel), ('IndexSelector', index_sel),
                                                       ('BrushIntervalSelector', br_intsel), ('MultiSelector', multi_sel),
                                                       ('None', None)]))

link((selection_interacts, 'value'), (fig, 'interaction'))
VBox([deb, fig, selection_interacts], align_self='stretch')
val1=data.groupby(["gender","age"])["distance"].agg(["sum"]).unstack()["sum"]
val1
val2=data.groupby(["gender","age"])["tripduration"].agg(["sum"]).unstack()["sum"]
val2
val1 = val1.dropna(axis=1)
val2 = val2.dropna(axis=1)
val3 = val1 * (60*60)/val2
val3<jupyter_output><empty_output><jupyter_text>Distance covered by age and gender<jupyter_code>val=data.groupby(["age","gender"]).sum()['distance'].unstack().dropna()
#print(val)
val.plot()<jupyter_output><empty_output><jupyter_text>Average biker speed by age and gender<jupyter_code>val1=data.groupby(["age","gender"]).sum()['tripduration'].unstack().dropna()
#print(val1)
val2=val*(60*60)/val1
val2.dropna().plot()<jupyter_output><empty_output><jupyter_text>Station wise activity and dates<jupyter_code>import ipywidgets
data.head()
    
loc1 = data.groupby("start station id").first()
location = loc1.loc[:,["start station longitude","start station latitude","start station name"]]
departure=data.groupby("start station id").count().iloc[:,[0]]
departure.columns=["Counts of Departure"]
#print(type(departure))
arrival= data.groupby("end station id").count().iloc[:,[0]]
arrival.columns=["Counts of Arrival"]
#print(type(arrival))
#joining arrival and departure
trip = departure.join(location).join(arrival)
trip.head()
loc1.head()
#data["end station id"]
loc2 = data.groupby(["start station id","end station id"]).first()
loc2.head()
loc3 = data.groupby(["start station id","hour"]).first()
loc3.head()
loc3 = data.groupby(["start station id","hour"]).sum()["bikeid"].plot()
loc3 = data.groupby(["start station id","hour"]).first()
val = data.groupby(["start station id"]).first()["hour"]
val = data[(data["start station id"]==72) & (data["end station id"]==379)]
val.head()
bike = val.groupby(["hour"]).count().iloc[:,[11]].reset_index()
bike.head()
from bokeh.plotting import figure, output_file, show

output_file("line.html")
p = figure(plot_width=400, plot_height=400)
p.line(bike["hour"], bike["bikeid"], line_width=2)
show(p)
start_stations = dict(zip(data["start station name"], data["start station id"]))
start_stations["None"] = None
end_stations = dict(zip(data["end station name"], data["end station id"]))
end_stations["None"]=None<jupyter_output><empty_output><jupyter_text>Number of trips per hour corresponding to start station<jupyter_code>import ipywidgets
from ipywidgets import interact
from bokeh.models import HoverTool
hover = HoverTool(tooltips=[
    ("Hour of the day: ", "$x"),
    ("Trips: ", "$y{00}"),
])
def f(start_station):
    val = data[data["start station id"]==start_station]
    bike = val.groupby(["hour"]).count().iloc[:,[11]].reset_index()
    output_file("line.html")
    p = figure(plot_width=400, plot_height=400,tools=[hover])
    p.line(bike["hour"], bike["bikeid"], line_width=2)
    show(p)

interact(f,start_station=start_stations)
import ipywidgets
from ipywidgets import interact
from bokeh.models import HoverTool
hover = HoverTool(tooltips=[
    ("Hour of the day: ", "$x"),
    ("Trips: ", "$y{00}"),
])
def f(start_station,end_station):
    val = data[(data["start station id"]==start_station) & (data["end station id"]==end_station)]
    bike = val.groupby(["hour"]).count().iloc[:,[11]].reset_index()
    output_file("line.html")
    p = figure(plot_width=400, plot_height=400,tools=[hover])
    p.line(bike["hour"], bike["bikeid"], line_width=2)
    show(p)

interact(f,start_station=start_stations,end_station=end_stations)
data.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1696645109135004, 'fraction_numerical': 0.015359741309620048, 'mean_word_length': 6.68997668997669, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '120166', 'license': 'MIT', 'n_tokens_mistral': 3661, 'n_tokens_neox': 3527, 'n_words': 644, 'path': 'docs/Understanding the dataset.ipynb', 'repo_name': 'garimag2/Viz_Project_Data_Wizards', 'size': '9896'}