# ---
# 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
# ---

# <font size="+5">#01. Data Tables, Plots & Basic Concepts of Programming</font>

# <ul>
#     <li>Doubts? → Ask me in <img src="https://emoji.gg/assets/emoji/3970-discord.png" style="height: 1em; vertical-align: middle;"> <a href="https://discord.gg/cmB3KGsqMy">Discord</a></li>
#     <li>Tutorials → <img src="https://openmoji.org/php/download_asset.php?type=emoji&emoji_hexcode=E044&emoji_variant=color" style="height: 1em; vertical-align: middle;"> <a href="https://www.youtube.com/channel/UCovCte2I3loteQE_kRsfQcw">YouTube</a></li>
#     <li>Book Private Lessons → <span style="color: orange">@</span> <a href="https://sotastica.com/reservar">sotastica</a></li>
# </ul>

# # Load the Data

# > By executing the following lines:
#
# ```python
# import seaborn as sns
# sns.get_dataset_names()
# ```
#
# > We will se a list of possible datasets that we can load to python by just typing the name in the function. For example:
#
# ```python
# sns.load_dataset(name='mpg')
# ```

# +
import seaborn as sns

df = sns.load_dataset("mpg")
# -

df.cylinders

df

# +
import seaborn as sns

sns.load_dataset("cylinders")
# -

sns.load_dataset(name="mpg")

# # Scatterplot with 2 Variables

# > - Variable in X Axis
# > - Variable in Y Axis

sns.scatterplot(data = df, x = "acceleration", y = "horsepower")

# # Scatterplot with 3 variables

# > - Variable in X Axis
# > - Variable in Y Axis
# > - Color each point regarding a different value in a column

grid = sns.FacetGrid(df, col = "origin", hue = "origin", col_wrap=5)
grid.map(sns.scatterplot, "acceleration", "horsepower");

sns.scatterplot(x='acceleration', y='horsepower', data=df, hue='origin')

# # Other Data Visualization Figures

# > We'll head over the 3 main libraries used in Python to visualize data: `matplotlib`, `seaborn` and `plotly`.
# >
# > We'll reproduce at least one example from the links provided below. Therefore, we need to:
# >
# > 1. Click in the link
# > 2. Pick up an example
# > 3. Copy-paste the lines of code
# > 4. Run the code

# ## Seaborn Example Gallery

# > - https://seaborn.pydata.org/examples/index.html

# +
import seaborn as sns

sns.set_theme(style="darkgrid")
df = sns.load_dataset("penguins")
sns.displot(
    df, x="flipper_length_mm", col="species", row="sex",
    binwidth=3, height=3, facet_kws=dict(margin_titles=True),
)
# -

# ## Matplotlib Example Gallery

# > - https://towardsdatascience.com/matplotlib-tutorial-with-code-for-pythons-powerful-data-visualization-tool-8ec458423c5e

# +
from sklearn import datasets
import matplotlib.pyplot as plt
iris = datasets.load_iris()
X_iris = iris.data
Y_iris = iris.target
average = X_iris[Y_iris == 0].mean(axis=0)

plt.bar(iris.feature_names, average)
plt.title("Bar Chart Setosa Averages")
plt.ylabel("Average (in cm)")
plt.show()
# -

# ## Plotly Example Gallery

# > - https://plotly.com/python/

hola

import plotly.graph_objects as go
fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"
)
fig.show()

# # Load again the DataFrame from Exercise 1

# ```python
# df = sns.load_dataset(name='mpg')
# df.head()
# ```

df= sns.load_dataset("mpg")
df.head()

# # Repeat the same Visualization Figures 

# > It's very easy to copy-paste. Nevertheless, we must **copy-paste with criteria**: identify what to copy and what to modify to solve our problem. Therefore:
# >
# > - We'll try to emulate each one of the previous exercise figures with the `DataFrame` that we used in Exercise 1.

# ## Seaborn

df

# +
import seaborn as sns

sns.set_theme(style="darkgrid")
df = sns.load_dataset("mpg")
sns.displot(df, x="horsepower", col="origin", row="cylinders",
            binwidth=3, height=3, facet_kws=dict(margin_titles=True))
# -

# ## Matplotlib



# ## Plotly



# # Achieved Goals

# _Double click on **this cell** and place an `X` inside the square brackets (i.e., [X]) if you think you understand the goal:_
#
# - [ ] Identify the **Elements of Programming** thanks to the syntax.
# - [ ] Use `functions` that belongs to external `libraries`.
# - [ ] Get _the machine to work for you, not against you_.
#   - [ ] `shift + tab` to ask help to Python.
#   - [ ] `tab` to ask Python for suggestions.
# - [ ] Understand that a `dog` doesn't make `miau()`. But, rather `guau()`... the same way a `DataFrame` cannot `fly()` (i.e., `DataFrame.fly()`?).
# - [ ] All roads lead to Rome; We can achieve the **the same result with different lines of code**.
#   - We reproduced a scatterplot using 3 different lines of code.
# - [ ] Different **`libraries`** may have `functions()` that do the **same thing**.
#   - `matplotlib`, `seaborn` & `plotly` makes outstanding Visualization Figures
#   - But you probably wouldn't use `plotly` on a paper. Unless we are on Harry Potter 😜
# - [ ] Understand that **coding is a matter of necessity**. Not a serie of mechanical steps to achieve a goal.
#   - You need to create art (code) by solving one problem at a time.
# - [ ] Understand that **there  isn't a unique solution**.
#   - We can achieve the same result with different approaches.
#   - For example, changing the colors of the points.

StarcoderdataJupyterScriptsDedupFiltered