<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Coding in Color</title>
    <description>A lot of the code we use in data science is really simple, but we get intimidated because there is so much out there, and the code just starts to blend together. Let&apos;s get some examples and really get an idea for the simplicity of data visualization.</description>
    <link>https://kimmybeew.github.io/</link>
    <atom:link href="https://kimmybeew.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 30 Jan 2025 21:51:33 +0000</pubDate>
    <lastBuildDate>Thu, 30 Jan 2025 21:51:33 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator><item>
        <title>When You Wish Upon a Streamlit App: Disney Data continued</title>
        <description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;D&lt;/span&gt;ata visualization gets even more memorable when it can be played with. Static images can show you a good overview, but if a picture&apos;s worth a thousand words, then a movie should be worth 100 million. Pull up the &lt;a href=&quot;https://disney-stocks-and-movies.streamlit.app/&quot;&gt;webapp&lt;/a&gt; side by side if you&apos;d like to see the value. (And check out the GitHub &lt;a href=&quot;https://github.com/KimmyBeeW/streamlit-disney-datavis/&quot;&gt;repo&lt;/a&gt; for the full code I used.) Together we can answer the question: How has Disney been doing as a company over the last few years?&lt;/p&gt;

&lt;h3 id=&quot;how-to-build-a-streamlit-app&quot;&gt;How to build a Streamlit app&lt;/h3&gt;
&lt;p&gt;You can attach your github account to streamlit and deploy an app directly from there by signing up for the free &lt;a href=&quot;https://streamlit.io/cloud&quot;&gt;community cloud&lt;/a&gt; and signing in with your github account. Once you have an account, you can deploy an app by someone else, or initialize a new repo for your app, create a main.py file (or whatever you’d like to call it) and a requirements.txt file, and get to writing. If you’re making one for yourself, you’ll need to import the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;streamlit&lt;/code&gt; library, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plotly&lt;/code&gt; for interactive plots, and probably a few others. My import list on main.py looked like this for this app:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import streamlit as st
import numpy as np
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt
from io import BytesIO
import plotly.graph_objects as go
from plotly.subplots import make_subplots
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Any and all libraries that you need for the app need to be included on new lines in your requirements.txt file (like &lt;a href=&quot;https://github.com/KimmyBeeW/streamlit-disney-datavis/blob/main/requirements.txt&quot;&gt;this&lt;/a&gt;). Once all that is done, you can deploy your app and see what your code affects in real time.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href=&quot;https://share.streamlit.io/&quot;&gt;share.streamlit.io&lt;/a&gt; and click “Create app” in the top right corner. If you’re doing it through GitHub like me you’ll select the “Deploy a public app from GitHub”. Now select the repo that your code is in, select the main or master branch, select the title of your main.py file, and create a custom url for your app. The url I chose for my app is &lt;a href=&quot;https://disney-stocks-and-movies.streamlit.app/&quot;&gt;disney-stocks-and-movies.streamlit.app&lt;/a&gt;. Select deploy and you’ll be able to visit your app at the link you just created.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/streamlit-createapp.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Before you do any data visualization you’ll need some data to visualize. Since I wanted to find out more about my Disney data, I read that in. In your main.py file under the import statements you can read in as many data sets as you want by using code that looks like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;@st.cache_data  # the decorator so the app can read the data
def load_stock_data():  # function for data source
    url = &apos;https://github.com/KimmyBeeW/Disney-Web-Scraping/raw/main/datasets/all_disney_stocks.csv&apos;
    stocks = pd.read_csv(url, index_col = 0)  # read it into a DataFrame
    return stocks  # return DataFrame

stocks = load_stock_data()  # call the function and assign to variable
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And don’t forget to give your new app a title!&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;st.title(&quot;Disney Stocks and Disney Brands Box Office Numbers&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;play-with-the-data&quot;&gt;Play with the Data&lt;/h3&gt;
&lt;p&gt;It’s now time to add your interactive elements and make some discoveries about your data! You can use tools like a sidebar to really optimize your data visualization.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;with st.sidebar:  # interactive side bar
    brands = st.radio(&apos;Brand name&apos;, [&apos;Marvel&apos;, &apos;Lucasfilm&apos;, &apos;Pixar&apos;, &apos;Walt Disney Animation&apos;, &apos;Disney Channel&apos;, &apos;Disneytoon Studios&apos;, &apos;Disneynature&apos;, &apos;Blue Sky Studios&apos;])

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or maybe you’d like to use different tabs to visualize your data. I always love a good line graph for time data:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tab1, tab2, tab3, tab4 = st.tabs([&quot;Disney Stocks&quot;, &quot;2nd tab&quot;, &quot;3rd tab&quot;, &quot;4th tab&quot;]) # switch out the names obviously
with tab1:
    # slider for range of the graph dates
    startyear_input = st.slider(&apos;Start Year&apos;, min_value = 1962, max_value=2024, value=2021)
    endyear_input = st.slider(&apos;End Year&apos;, min_value = 1962, max_value=2024, value=2024)
    filt_stocks = stocks[(stocks[&apos;Date&apos;] &amp;gt;= pd.Timestamp(startyear_input, 1, 1)) &amp;amp; 
                         (stocks[&apos;Date&apos;] &amp;lt;= pd.Timestamp(endyear_input, 12, 31))].copy()
    # make it possible to see all four lines
    mlt_stocks = filt_stocks.melt(id_vars=&apos;Date&apos;, value_vars=[&apos;Close&apos;, &apos;Open&apos;, &apos;High&apos;, &apos;Low&apos;], 
                                     var_name=&apos;Type&apos;, value_name=&apos;Price ($)&apos;)
    # custom colors
    val_colors = {&apos;High&apos;: &apos;#29b6f6&apos;, &apos;Low&apos;: &apos;#a80930&apos;,
                     &apos;Close&apos;: &apos;#efb71d&apos;, &apos;Open&apos;: &apos;#2bb007&apos;}
    # plot the stocks
    fig = px.line(mlt_stocks, x=&apos;Date&apos;, y=&apos;Price ($)&apos;, color=&apos;Type&apos;,
                  title=&apos;Disney Stock Prices Over Time&apos;,
                  labels={&apos;Price&apos;: &apos;Stock Price&apos;, &apos;Type&apos;: &apos;Price Type&apos;},
                  color_discrete_map=val_colors)
    st.plotly_chart(fig)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now I can see a wide range of years and really put into perspecive how Disney’s stocks are doing. Hovering over the peak allows me to see that Disney’s highest stock price in the last few years was $203 back in March of 2021 and that it hasn’t been that high since. But I could play with the slider and go check out how Disney was doing back in the 1960s if I wanted to.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/stmlt-linegraph.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Those sidebar buttons from earlier can be used to look at the data from different brands so you can see patterns like peaks in the late 2010s and how none of the newer movies have even gotten close to the same opening revenue. Of course part of that can be explained by the change in culture following the pandemic in 2020, but it also coincides with the release of Disney+ in November of 2019.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/stmlt-marvel-scatter.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/stmlt-lucasfilm-scatter.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Interested in more ways to visualize your data? Me too! Streamlit has lots of resources for learning about their cool features like &lt;a href=&quot;https://docs.streamlit.io/develop/api-reference/widgets&quot;&gt;input widgets&lt;/a&gt;, &lt;a href=&quot;https://docs.streamlit.io/develop/api-reference/layout/st.tabs&quot;&gt;tabs&lt;/a&gt;, and the &lt;a href=&quot;https://docs.streamlit.io/develop/api-reference/layout/st.sidebar&quot;&gt;sidebar&lt;/a&gt;. And of course if you want to continue learning from my code, you can always check out my &lt;a href=&quot;https://github.com/KimmyBeeW/streamlit-disney-datavis&quot;&gt;repo&lt;/a&gt; and the code I used to implement the cool features in my &lt;a href=&quot;https://disney-stocks-and-movies.streamlit.app/&quot;&gt;streamlit app&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;at-last-i-see-the-light&quot;&gt;At Last I See The Light&lt;/h3&gt;
&lt;p&gt;Building my little app helped me see my data in a clearer light, and it really did help me understand the patterns I noticed before to a deeper level. The stocks are definitely sinking, and the movies are aligning with that pattern, but hopefully Disney can learn from its past mistakes and bring back the magic. For now I hope this little tutorial brought some magic to your life, and that you’ll continue to enjoy coding in &lt;a href=&quot;https://htmlcolorcodes.com/color-picker/&quot;&gt;color&lt;/a&gt;!&lt;/p&gt;

</description><description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;D&lt;/span&gt;ata visualization gets even more memorable when it can be played with. Static images can show you a good overview, but if a picture&apos;s worth a thousand words, then a movie should be worth 100 million. Pull up the &lt;a href=&quot;https://disney-stocks-and-movies.streamlit.app/&quot;&gt;webapp&lt;/a&gt; side by side if you&apos;d like to see the value. (And check out the GitHub &lt;a href=&quot;https://github.com/KimmyBeeW/streamlit-disney-datavis/&quot;&gt;repo&lt;/a&gt; for the full code I used.) Together we can answer the question: How has Disney been doing as a company over the last few years?&lt;/p&gt;

</description><pubDate>Wed, 04 Dec 2024 00:00:00 +0000</pubDate>
        <link>https://kimmybeew.github.io/blog/streamlit-disney-data-vis/</link>
        <guid isPermaLink="true">https://kimmybeew.github.io/blog/streamlit-disney-data-vis/</guid></item><item>
        <title>The Downfall of Disney? Once upon a Web Scraper</title>
        <description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;O&lt;/span&gt;kay, downfall may be a little dramatic, but if Disney continues at the rate it&apos;s going, I may not be far off. I used to be obsessed with the MCU. I loved watching all the theory videos on YouTube and was so excited every time a new movie was announced, but when, epic though it was, Endgame managed to kill off or fatally change many of my favorite characters, I knew the MCU, and Disney as a whole, would never be the same.&lt;/p&gt;

&lt;p&gt;Around the same time in 2019 and 2020 Disney’s live-action remakes churned out some interesting choices with a not-at-all-live-action “live action” Lion King including &lt;a href=&quot;https://youtu.be/DZr-VTULYQ8?si=H3eaDo2D2kChAh_x&quot;&gt;“Can You Feel the Love Tonight”&lt;/a&gt; sung in the middle of the day and the titular character of Mulan’s fighting spirit being replaced with &lt;a href=&quot;https://www.polygon.com/entertainment/2020/9/3/21419876/mulan-review-live-action-disney-plus&quot;&gt;magical chi superpowers&lt;/a&gt;, in other words completely missing the points of some of the old stories. The animations are still beautiful and the stories are still enjoyable, but it got me wondering if those changes, and the apparent emphasis on quantity over quality, was starting to hurt Disney as a business. So I took my newfound web-scraping skills to the &lt;a href=&quot;https://www.boxofficemojo.com/&quot;&gt;Box Office Mojo&lt;/a&gt; website and &lt;a href=&quot;https://finance.yahoo.com/quote/DIS/history/?period1=1571423893&amp;amp;period2=1729276688&quot;&gt;Yahoo! Finance&lt;/a&gt; to see what the movie theater goers and stock holders had to say.&lt;/p&gt;

&lt;h3 id=&quot;how-has-disney-been-doing-as-a-company-over-the-last-few-years&quot;&gt;How has Disney been doing as a company over the last few years?&lt;/h3&gt;
&lt;p&gt;Disney does more than just movies, so let’s look at how the shareholders view Disney’s success. I got this stock data from &lt;a href=&quot;https://finance.yahoo.com/quote/DIS/history/?period1=1571423893&amp;amp;period2=1729276688&quot;&gt;Yahoo! Finance&lt;/a&gt;, and you can see that, other than the obvious dip caused by the pandemic in March of 2020, Disney was on the rise until around February 2021, then fell again November of 2021, and hasn’t gone above $130 since the beginning of 2022. Which incidentally aligns with the terror that was “Doctor Strange in the Multiverse of Madness” (May 2022). It could be coincindence though.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/disstocks5yrs.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Because of the rise of inflation and the noteriaty of the company, Disney is still doing better than pre-2014, yet further evidence against them falling anytime soon. Loyal fans are still clinging on to the nostalgia of the past and the merch of the present, and there is no doubt that Disney is still a successful company. It’s just an interesting pattern to note before diving into the success of current movies.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/disstocks_allyrs.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;a-tale-as-old-as-box-office-numbers&quot;&gt;A tale as old as Box Office numbers&lt;/h3&gt;
&lt;p&gt;Now that we have an overview of what the shareholders think, let’s look at what actual movie-goers think. &lt;a href=&quot;https://www.boxofficemojo.com/brand/?ref_=bo_nb_gs_secondarytab&quot;&gt;Box Office Mojo&lt;/a&gt; has a really awesome collection of brands, their respective movies, and info about those movies’ lifetime gross income to date, max number of theaters, opening weekend gross income, opening number of theaters, release date, and distributer. It’s fun to look through their website, but I really wanted an aggregate of brands owned by disney, so I used web-scraping to look at the following brands from the &lt;a href=&quot;https://www.boxofficemojo.com/brand/?ref_=bo_nb_gs_secondarytab&quot;&gt;Box Office Mojo Website&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3732077058/&quot;&gt;Marvel Comics&lt;/a&gt; – Disney acquired Marvel Entertainment in 2009.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn4168284674/&quot;&gt;Lucasfilm&lt;/a&gt; – Disney purchased Lucasfilm in 2012.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3530750466/&quot;&gt;Pixar&lt;/a&gt; – Acquired by Disney in 2006.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3295869442/&quot;&gt;Walt Disney Animation Studios&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3430087170/&quot;&gt;Blue Sky Studios&lt;/a&gt; – Disney acquired Blue Sky as part of the 2019 purchase of 21st Century Fox, but it was shut down in 2021.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3446864386/&quot;&gt;Disney Channel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn4185061890/&quot;&gt;DisneyToon Studios&lt;/a&gt; – A division of Disney, closed in 2018.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.boxofficemojo.com/brand/bn3245537794/&quot;&gt;Disneynature&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mini-web-scraping-tutorial-for-python&quot;&gt;Mini Web-scraping tutorial for Python&lt;/h3&gt;
&lt;p&gt;When web-scraping data online, you must ALWAYS check the robots.txt file. It tells you what you can and should not scrape, and how fast you can scrape it. Nearly every domain has one, and if they don’t it is common curtesy to add a sleep timer. (Here is some example code since I didn’t need to use one in my web-scraping):&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;websites = []

for link in links:
    time.sleep(10)  # sleep timer for 10 seconds
    r = requests.get(link)
    bs = BeautifulSoup(r3.text)
    try:
        website = bs.find(&apos;div&apos;, {&apos;class&apos;: &apos;unique_tag_text_from_html&apos;}).find(&apos;a&apos;)[&apos;href&apos;]
    except:
        website = None
    websites.append(website)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I checked robots.txt by using my RequestGuard class in python to check that the urls I was scraping from weren’t part of the forbidden list, but I recently learned about the urllib in python that can do the same thing for you. Check out this &lt;a href=&quot;https://docs.python.org/3/library/urllib.robotparser.html&quot;&gt;brief overview&lt;/a&gt; to learn more. Everthing was good for my urls so I moved on to the actual data gathering.&lt;/p&gt;

&lt;p&gt;I used &lt;a href=&quot;https://www.crummy.com/software/BeautifulSoup/bs4/doc/&quot;&gt;bs4.BeautifulSoup&lt;/a&gt;, but if the website you’re trying to scrape has buttons that need clicking, you’ll want to use &lt;a href=&quot;https://www.zenrows.com/blog/selenium-vs-beautifulsoup&quot;&gt;Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now you simply inspect the pages HTML by right clicking on the page, hovering over the HTML parts until the data you want to scrape is highlighted and find the unique tags attched to those data points. For readability, I’d also recommend converting the data to a pandas &lt;a href=&quot;https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html&quot;&gt;DataFrame&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My code looks like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;url = &quot;https://www.boxofficemojo.com/brand/bn3732077058/&quot;
rg = RG(url)
if rg.can_follow_link(url):
    print(&quot;robot.txt allows scraping for this page&quot;) 

r = requests.get(url)
print(r.status_code)  # if it&apos;s 200 we&apos;re good to go

soup = BeautifulSoup(r.text)  # this gets the whole html soup object
container = soup.find(&apos;div&apos;, {&apos;class&apos;: &apos;a-section imdb-scroll-table mojo-gutter&apos;})  # a smaller chunk to make it easier to find names
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once you have a container, you get to play “find the pieces” with your data. When you know what the rows are contained in (usually something like a ‘tr’ table row tag.) Then you can iterate through and make a dataframe:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;items = container.find_all(&apos;tr&apos;)
ranks, titles, gross, max_theaters, opening_earnings, opening_num_thtrs, release_dates, studios = [], [], [], [], [], [], [], []
for row in items[1:]:
    rank = row.find(&apos;td&apos;, class_=&apos;mojo-field-type-rank&apos;).text
    ranks.append(rank)
    title = row.find(&apos;td&apos;, class_=&apos;mojo-field-type-release&apos;).text
    titles.append(title)
    life_gross = row.find  # etc etc (check out repo for full code)

# combine the lists to make a pandas DataFrame
df = pd.DataFrame({&apos;Rank&apos;: ranks, &apos;Title&apos;: titles, &apos;Gross Income&apos;: gross, &apos;Max Theaters&apos;: max_theaters, &apos;Opening Earnings&apos;: opening_earnings, &apos;Opening Num Theaters&apos;: opening_num_thtrs, &apos;Release Dates&apos;: release_dates, &apos;Studio&apos;: studios}).drop_duplicates().reset_index(drop=True)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;drum-roll-for-the-data-pulled&quot;&gt;Drum roll for the data pulled&lt;/h3&gt;
&lt;p&gt;After scraping the data from the different brands, I combined it into a csv with 204 movies, reranked them to align with the combination, and called it &lt;a href=&quot;https://github.com/KimmyBeeW/Disney-Web-Scraping/blob/main/datasets/disney_owned_movies.csv&quot;&gt;disney_owned_movies.csv&lt;/a&gt;. I realized that there were plenty of movies missing from the dataset not attatched to brands listed on Box Office Mojo, such as the Chronicles of Narnia movies, but my main points of interest revolved around Marvel, Pixar, and Walt Disney Animation, so I’ll leave adding the other Disney movies for you to explore if you’d like.&lt;/p&gt;

&lt;p&gt;Without further ado, here are the highlights, and you can decide what you think of Disney’s fate. Only time will truly tell.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/brandsGrossIncome.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Marvel is clearly Disney’s highest grossing brand at the moment, so it was a wise purchasing descision, but it also means Marvel plays a huge role in Disney’s success.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/earningsVSbrand.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And the number of opening theaters doesn’t always spell success, but it is interesting to note the power of releasing studio influence.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/earningsVSMaxTheaters.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;No surprise here, the movie attributes are pretty highly correlated (just look at the bottom left triangle) meaning that they’re all affected by the same thing or by each other.
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/correlationMovies.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And the one we’ve all been waiting for, Opening Earnings over Time:
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/earningsVStime.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;
And the zoomed in version:
&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/lastfive.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Notice the peaks in 2019 and 2022? Maybe I was right after all. The beginnings of a pattern are occuring and it doesn’t look too good for our heroes, especially when compared to the stock data we gathered earlier.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/disstocks5yrs.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For lifelong Disney fans, this data might evoke nostalgia for the golden era of box-office hits, but hopefully there is more good to come. It makes one wonder how the company will innovate in response to these challenges. It will be interesting to see if Disney pivots its strategies or doubles down on its streaming services. Could this signal the end of Disney’s box-office dominance? Only time will tell.&lt;/p&gt;

&lt;h3 id=&quot;want-to-do-it-yourself&quot;&gt;Want to do it yourself?&lt;/h3&gt;
&lt;p&gt;Check out my &lt;a href=&quot;https://github.com/KimmyBeeW/Disney-Web-Scraping&quot;&gt;repo&lt;/a&gt; with all of the code I used to webscrape the Box Offic Mojo website, my RequestGuard file for parsing the robots.txt files, the data I gathered, and some helpful links I found. Web scraping is a lot easier than I remembered it being, it just takes some puzzling and time. Go analyze data about your own interests, and always remember to have fun coding in color!&lt;/p&gt;
</description><description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;O&lt;/span&gt;kay, downfall may be a little dramatic, but if Disney continues at the rate it&apos;s going, I may not be far off. I used to be obsessed with the MCU. I loved watching all the theory videos on YouTube and was so excited every time a new movie was announced, but when, epic though it was, Endgame managed to kill off or fatally change many of my favorite characters, I knew the MCU, and Disney as a whole, would never be the same.&lt;/p&gt;

</description><pubDate>Wed, 13 Nov 2024 00:00:00 +0000</pubDate>
        <link>https://kimmybeew.github.io/blog/downfall-of-disney/</link>
        <guid isPermaLink="true">https://kimmybeew.github.io/blog/downfall-of-disney/</guid></item><item>
        <title>Data&apos;s Paintbrush in Python</title>
        <description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;T&lt;/span&gt;he Data Visualization aspect of Data Science can be scary with how many tools, IDEs, coding languages, and platforms that are available. Plus, if you&apos;re into Data Science, you may already be familiar with R and RStudio, but outside of stats, R is hardly used, and  it&apos;s always good to flesh out your portfolio of skills. So take a deep breath. Let&apos;s go back to basics and start with one of the most popular coding languages today: PYTHON&lt;/p&gt;

&lt;h3 id=&quot;where-to-get-started-set-up&quot;&gt;Where to get started: set up&lt;/h3&gt;
&lt;p&gt;Since this is a tutorial on how to create simple plots in Python we need to have a place to use it, so if you’re coding in python, you’ll really want an interface. It doesn’t need to be anything fancy. You can use an IDE like PyCharm, a text-editor like VS Code, or a browser-based tool like Google Collab. All three of which have free options: for &lt;a href=&quot;https://www.jetbrains.com/pycharm/download/?section=mac&quot;&gt;PyCharm Community Edition&lt;/a&gt; scroll down to Community Edition and select the dropdown for your computer type, for &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;VS Code&lt;/a&gt; just select the download button, and &lt;a href=&quot;https://colab.research.google.com/&quot;&gt;Google Colab&lt;/a&gt; is available to anyone with a google account.&lt;/p&gt;

&lt;p&gt;Now you’ll want to install and import a couple of libraries. For the sake of this tutorial, we’re going to use matplotlib.pyplot, and numpy. If it’s your first time using these libraries in an IDE, Text Editor, or CLI, you’ll need to install them. This line in the computer terminal is how I install it on my mac (same for a Linux): `&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 -m pip install &quot;matplotlib&quot;&lt;/code&gt;`
Pretty similar line for a windows: `&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;py -m pip install &quot;numpy&quot;&lt;/code&gt;`&lt;/p&gt;

&lt;p&gt;Or you can follow this &lt;a href=&quot;https://packaging.python.org/en/latest/tutorials/installing-packages/&quot;&gt;tutorial&lt;/a&gt; by Python if you get stuck.&lt;/p&gt;

&lt;p&gt;Once the library has been installed (which you’ll only need to do once), you’ll import the library and shorten the name you use to reference. Import libraries at the top of your file:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import matplotlib.pyplot as plt
import numpy as np
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we’re ready to get graphing!&lt;/p&gt;

&lt;h3 id=&quot;plot-production&quot;&gt;Plot Production&lt;/h3&gt;
&lt;h4 id=&quot;line-graphs&quot;&gt;Line Graphs&lt;/h4&gt;
&lt;p&gt;Line Graphs are a great way to visualize trends in data. They’re used for line of best fit, displaying the relationship between simple datasets or two parts of a more complex dataset. The x-axis is typically used to measure the time over which data is measured. Examples of line graphs include: stocks over hours, weight over months, price over season, # of ticket sales per day, etc.&lt;/p&gt;

&lt;p&gt;The first part of the code for the line graph is defining our line graph function and looks like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def line(x_points, y_points, color):
    plt.plot(x_points, y_points, color = color)
    plt.show()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;.plot and .show come from the matplotlib library and accessed using our shortcut “plt”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The function by itself doesn’t do anything because we need to define the data. You can do that using two lists of the same length:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [1, 4, 4, 3, 6, 8, 9, 11, 13]
line(x, y, &apos;b&apos;)  # calls on the function we just made
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/line-graph1.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Or you can define a matrix/array with numpy:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data = np.array([[1, 13], [2, 11], [3, 10], [4, 8], [5, 7], [6, 6], [7, 4], [8, 2], [9, -1]])
line(data[:, 0], data[:, 1], &apos;g&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/line-graph2.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;What if you want to add more that one line? Well, matplotlib.pyplot offers many colors which can help you distinguish lines, and putting multiple plt.plots before a plt.show will let you put multiple lines on a single graph.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def colors():
    x_points = [0, 1, 2, 3, 4, 5]
    line1_y_points = [1, 2, 3, 4, 5, 6]
    line2_y_points = [2, 3, 4, 5, 6, 7]
    line3_y_points = [3, 4, 5, 6, 7, 8]
    line4_y_points = [4, 5, 6, 7, 8, 9]
    line5_y_points = [5, 6, 7, 8, 9, 10]
    line6_y_points = [6, 7, 8, 9, 10, 11]
    line7_y_points = [7, 8, 9, 10, 11, 12]
    line8_y_points = [8, 9, 10, 11, 12, 13]

    plt.plot(x_points, line1_y_points, &apos;r&apos;)  # red
    plt.plot(x_points, line2_y_points, &apos;g&apos;)  # green
    plt.plot(x_points, line3_y_points, &apos;b&apos;)  # blue
    plt.plot(x_points, line4_y_points, &apos;c&apos;)  # cyan
    plt.plot(x_points, line5_y_points, &apos;m&apos;)  # magenta
    plt.plot(x_points, line6_y_points, &apos;y&apos;)  # yellow
    plt.plot(x_points, line7_y_points, &apos;k&apos;)  # black
    plt.plot(x_points, line8_y_points, &apos;w&apos;)  # white

    plt.show()

colors()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/multilines.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Adding labels adds even more info! You could say it’s pretty cool.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def multi_lines_and_labels():
    x_points = [0, 1, 2, 3, 4, 5]
    y1_points = [6, 7, 8, 9, 10, 10]
    y2_points = [4, 5, 6, 5, 7, 10]

    plt.plot(x_points, y1_points, label=&quot;You&quot;, color = &apos;b&apos;)
    plt.plot(x_points, y2_points, label=&quot;Me&quot;, color = &apos;r&apos;)

    plt.title(&quot;Our Coolness Levels&quot;)
    plt.xlabel(&quot;Months learning Data Science&quot;)
    plt.ylabel(&quot;Coolness Level&quot;)

    plt.legend()
    plt.show()

multi_lines_and_labels()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/cool-line-graph.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;scatter-plots&quot;&gt;Scatter Plots&lt;/h4&gt;
&lt;p&gt;Another way to visualize the relationship between two data catagories is a scatter plot. Rather than looking at the general trend line, scatter plots allow us to see points and their density. It also makes it easier to see points that have repeated x or y values.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def scatter(x_points, y_points):
    plt.scatter(x_points, y_points)
    plt.show()


x3 = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7]
y3 = [1, 3, 2, 3, 2, 4, 5, 5, 5.5, 6.5, 7]
scatter(x3, y3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/scatter.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;bar-graphs&quot;&gt;Bar Graphs&lt;/h4&gt;
&lt;p&gt;Bar Graphs are a way to visualize the counts of your different factor levels or categorical data.&lt;/p&gt;

&lt;p&gt;If you had a bag of fruit, and wanted to see how many of each type you have, bar graphs are a way to see that! In this example we have a lot more Apples than any other fruit.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def bar(categories, counts):
    plt.bar(categories, counts)
    plt.show()


fruit = [&apos;Apple&apos;, &apos;Banana&apos;, &apos;Kiwi&apos;, &apos;Orange&apos;]
f_counts = [5, 1, 3, 1]
bar(fruit, f_counts)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/bar.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;histograms&quot;&gt;Histograms&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def hist(frequencies):
  plt.hist(frequencies, [1, 2, 3, 4, 5, 6], color = &apos;g&apos;)
  plt.show()

freq = [
    1, 1, 1, 1, 1, 1,  # 6 ones
    2, 2, 2,  # 3 twos
    3,  # 1 three
    4, 4,  # 2 fours
    5  # 1 five
]
hist(freq)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/histogram.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;density-plot&quot;&gt;Density Plot&lt;/h4&gt;
&lt;p&gt;A density plot is used for the same thing as a histogram, but is a more accurate way to view the changes in data.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import numpy as np
import seaborn as sns
data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8
sns.set_style(&apos;whitegrid&apos;)
sns.kdeplot(np.array(data), bw_method=0.5)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/density.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;pie-charts-the-bane-of-statisticians-existances&quot;&gt;Pie Charts: The Bane of Statisticians Existances&lt;/h4&gt;
&lt;p&gt;Seriously, do not use pie charts for stats. Pie charts make it hard to actually tell the proportions between real data, so this is only for your information. Use at your own risk.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def pie():
    counts = [4, 1, 2, 3]
    plt.pie(counts)
    plt.show()
pie()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://kimmybeew.github.io//stat-blog/assets/img/pie.png&quot; alt=&quot;&quot; class=&quot;center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;you-can-do-it&quot;&gt;You can do it!&lt;/h3&gt;
&lt;p&gt;Granted, those were just the basics of data visualization in python, but everyone’s got to start somewhere. In my experience, I learn how to code best when I copy someone elses code and turn it into my own thing, so I invite you to do the same. Get PyCharm, VS Code, or Google Collab and try out these graphs for yourself. Switch up the numbers, colors, and data, and don’t be afraid to use Google or ChatGPT for ideas on how to expand the functionality of the graphs. If you want to go even further, explore these other &lt;a href=&quot;https://www.index.dev/blog/top-10-python-libraries-for-data-visualization&quot;&gt;data visualization libraries&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for being willing to explore data visualization in python with me. Good luck coding in color!&lt;/p&gt;
</description><description>&lt;p class=&quot;intro&quot;&gt;&lt;span class=&quot;dropcap&quot;&gt;T&lt;/span&gt;he Data Visualization aspect of Data Science can be scary with how many tools, IDEs, coding languages, and platforms that are available. Plus, if you&apos;re into Data Science, you may already be familiar with R and RStudio, but outside of stats, R is hardly used, and  it&apos;s always good to flesh out your portfolio of skills. So take a deep breath. Let&apos;s go back to basics and start with one of the most popular coding languages today: PYTHON&lt;/p&gt;

</description><pubDate>Fri, 20 Sep 2024 00:00:00 +0000</pubDate>
        <link>https://kimmybeew.github.io/blog/datas-paintbrush-in-python/</link>
        <guid isPermaLink="true">https://kimmybeew.github.io/blog/datas-paintbrush-in-python/</guid></item></channel>
</rss>
