# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Change various plt values and see the effect - That is the only thing to do with this notebook

# widget for jupyterlab, otherwise inline works fine for jupyter notebook
# %matplotlib inline 
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

# Have to restart notebook for style change
plt.style.available

# Read a csv file. df stands for DataFrame
df = pd.read_csv('../height_weight.csv')
df

# notice the object reference is also being printed
df.plot()

# assign to remove object reference. Index is used for x axis, and each column is plotted on y axis
ax = df.plot()

# subplots to put each column in its own plot 
ax = df.plot(subplots=True)

# Add a title 
ax = df.plot(subplots=True, title="Height and Weight")

# plot specific column (observe how legend is not present when a column is selected, hence title helps)
ax = df['weight'].plot(title="Weight")

# or just use legend=True
ax = df['weight'].plot(title="Weight", legend=True)

# Lets change x axis and not taking default index of dataframe. Lets say we want to plot height corresponding to weight
ax = df.plot(title="Height vs. weight", x='weight', y='height')

# # Histogram

# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.hist.html
ax = df['weight'].plot.hist()

# Increase bins to spread out points, otherwise hist() will stuff all bars together like the above one
ax = df['weight'].plot.hist(bins=100)

# # Box plot

# In descriptive statistics, a box plot or boxplot is a method for graphically depicting groups of 
# numerical data through their quartiles. Box plots may also have lines extending vertically from the boxes (whiskers) indicating variability outside the upper and lower quartiles, 
# hence the terms box-and-whisker plot and box-and-whisker diagram. 
ax = df['weight'].plot.box()

# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.boxplot.html
ax = df.boxplot(column=['weight'])

ax = df.boxplot(column=['weight','height','repwt','repht'])

ax = df.boxplot(column=['weight','height','repwt','repht'], by='sex')

# # Pie Chart

import pandas as pd
df = pd.read_csv('../Real_Estate_Sales_2001-2017.csv')

df.info()

df['ListYear'].unique()

df_share_by_year = df['ListYear'].value_counts()
df_share_by_year

df_share_by_year.plot.pie()

df['PropertyType'].value_counts().plot.pie()

# # Bar graph

top_5 = df_share_by_year[:5]

top_5.plot.bar(title='Top 5')

top_5.plot.pie()

# # Excercises with Real estate data

df.info()

# What is the average value by PropertyType ?
averages = df.groupby(['PropertyType']).mean().reset_index()
averages

ax = averages.plot.bar(title='Average sale by Property Type',x='PropertyType',y='SaleAmount')

# # Horizontal Bar plot

ax = averages.plot.barh(title='Average sale by Property Type',x='PropertyType',y='SaleAmount')

StarcoderdataJupyterScriptsDedupFiltered