<jupyter_start><jupyter_text>2021-10-05 Registered Nurses https://github.com/rfordatascience/tidytuesday/blob/master/data/2021/2021-10-05/readme.md Choropleth Map - Done Text annotation - Done<jupyter_code>import pandas as pd
import plotly.graph_objects as go
import plotly.io as pio
import plotly.express as px
pio.renderers.default='notebook'
import os
df=pd.read_csv ('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-05/nurses.csv')
df.head()
df.columns
df_red=df[['State', 'Year','Total Employed RN','Annual Salary Avg','Annual Salary Median']]
code = {'Alabama': 'AL',
        'Alaska': 'AK',
        'Arizona': 'AZ',
        'Arkansas': 'AR',
        'California': 'CA',
        'Colorado': 'CO',
        'Connecticut': 'CT',
        'Delaware': 'DE',
        'District of Columbia': 'DC',
        'Florida': 'FL',
        'Georgia': 'GA',
        'Hawaii': 'HI',
        'Idaho': 'ID',
        'Illinois': 'IL',
        'Indiana': 'IN',
        'Iowa': 'IA',
        'Kansas': 'KS',
        'Kentucky': 'KY',
        'Louisiana': 'LA',
        'Maine': 'ME',
        'Maryland': 'MD',
        'Massachusetts': 'MA',
        'Michigan': 'MI',
        'Minnesota': 'MN',
        'Mississippi': 'MS',
        'Missouri': 'MO',
        'Montana': 'MT',
        'Nebraska': 'NE',
        'Nevada': 'NV',
        'New Hampshire': 'NH',
        'New Jersey': 'NJ',
        'New Mexico': 'NM',
        'New York': 'NY',
        'North Carolina': 'NC',
        'North Dakota': 'ND',
        'Ohio': 'OH',
        'Oklahoma': 'OK',
        'Oregon': 'OR',
        'Pennsylvania': 'PA',
        'Rhode Island': 'RI',
        'South Carolina': 'SC',
        'South Dakota': 'SD',
        'Tennessee': 'TN',
        'Texas': 'TX',
        'Utah': 'UT',
        'Vermont': 'VT',
        'Virginia': 'VA',
        'Washington': 'WA',
        'West Virginia': 'WV',
        'Wisconsin': 'WI',
        'Wyoming': 'WY'}
df_red['Code'] = df_red['State'].map(code)
df_red.head()
df_red.sort_values(by='Year', ascending=True,inplace=True)
fig = px.choropleth(df_red,
                    locations='Code',
                    color='Total Employed RN',
                    color_continuous_scale='spectral_r',
                    animation_frame="Year",
                    hover_name='State',
                    locationmode='USA-states',
                    labels={'Total Employed RN':'Total Employed Nurses'},
                    scope='usa',
                    title='Total Registered Nurses over Time'
                    )
fig.show()
# Display Output in production
img_bytes = fig.to_image(format="png")
from IPython.display import Image
Image(img_bytes)
df_red.columns
fig = px.choropleth(df_red,
                    locations='Code',
                    color='Annual Salary Median',
                    color_continuous_scale='spectral_r',
                    animation_frame="Year",
                    hover_name='State',
                    locationmode='USA-states',
                    #labels={'Total Employed RN':'Total Employed Nurses'},
                    scope='usa',
                    title='Median Yearly Salary of the Nurses over Time'
                    )
fig.show()
# Display Output in production
img_bytes = fig.to_image(format="png")
from IPython.display import Image
Image(img_bytes)
df_red_2020= df_red.loc[df_red.Year==2020]
fig = px.scatter(df_red_2020, x="Annual Salary Median", y="Total Employed RN", trendline="ols",hover_name='State')


fig.add_annotation(
            x=118400,
            y=311000,
            showarrow=True,
            arrowhead=1,
            text="High Demand and Value",
            textangle=0)

fig.add_annotation(
            x=33000,
            y=22000,
            showarrow=True,
            arrowhead=1,
            text="Low Demand and Value",
            textangle=0)



fig.show()
# Display Output in production
img_bytes = fig.to_image(format="png")
from IPython.display import Image
Image(img_bytes)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup