<jupyter_start><jupyter_text>Reading Data<jupyter_code>#Read CSV file into a pandas dataframe
data = pd.read_csv("Fremont_Bridge_Bicycle_Counter.csv")
data.head()<jupyter_output><empty_output><jupyter_text>Data Manipulation<jupyter_code># 2.1> Create new column: TOtal_Bicycle_Count
data['Total_Bicycle_Count'] = data['Fremont Bridge East Sidewalk'] + data['Fremont Bridge West Sidewalk']
data.head()
#Check data types for each column in the data
data.dtypes
#Covert Date column to datetime
data['Date'] = pd.to_datetime(data['Date'])
data.dtypes
# 2.2> Extract Hour from the Date into a new column
data['Hour'] = data['Date'].dt.hour

# 2.3> Extract Year from the Date into a new column
data['Year'] = data['Date'].dt.year
data.head()
# 3> Filter out all rows except for Year = 2016

data_2016 = data[data['Year'] == 2016]
data_2016.head()<jupyter_output><empty_output><jupyter_text>Exploratory Analysis<jupyter_code># 4> Plot total bicycle counts by hour 

total_bicycle_hourly = data.groupby("Hour")["Total_Bicycle_Count"].sum()
total_bicycle_hourly = pd.DataFrame(total_bicycle_hourly).reset_index()

# create bar plot
fig, ax = plt.subplots(figsize=(12,8))
ax.bar(x=total_bicycle_hourly["Hour"], height=total_bicycle_hourly["Total_Bicycle_Count"],)
ax.set_xticks(total_bicycle_hourly["Hour"])

#I wanted to highlight the maximum in the plot, so used this approach. 
#reference: https://stackoverflow.com/questions/20394091/pandas-matplotlib-make-one-color-in-barplot-stand-out
for bar in ax.patches:
    bar.set_facecolor('#888888')

highlight = total_bicycle_hourly['Total_Bicycle_Count'].idxmax()
pos = total_bicycle_hourly.index.get_loc(highlight)

ax.patches[pos].set_facecolor('#aa3033')
# set chart title and axis labels
plt.xlabel("Hour")
plt.ylabel("Total Bicycle Count")

plt.show()<jupyter_output><empty_output><jupyter_text>Arithmetic Operations<jupyter_code># 5> Find on average which is the busiest hour of the day
avg_traffic_hour = data.groupby("Hour")["Total_Bicycle_Count"].mean()
avg_traffic_hour = pd.DataFrame(avg_traffic_hour)

avg_traffic_hour[avg_traffic_hour["Total_Bicycle_Count"] == max(avg_traffic_hour["Total_Bicycle_Count"])]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12745545911375056, 'fraction_numerical': 0.021014161717679305, 'mean_word_length': 7.866396761133603, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '456436', 'license': 'MIT', 'n_tokens_mistral': 846, 'n_tokens_neox': 796, 'n_words': 159, 'path': 'Analysis/Homework_1.ipynb', 'repo_name': 'uwseds-sp20/homework-1-manipulating-data-Aniruddha2994', 'size': '2189'}