<jupyter_start><jupyter_text>Read hard drive failure rates data from clipboard<jupyter_code>df = pd.read_clipboard()<jupyter_output><empty_output><jupyter_text>Sneak peak at the data<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>Remove percent symbol and convert "VALUE" column as float type<jupyter_code>df.VALUE = df.VALUE.str.replace('%','')
df.VALUE = df.VALUE.astype(float)<jupyter_output><empty_output><jupyter_text>States with highest hard drive failures<jupyter_code>df.sort_values(by='VALUE', ascending=False).head(10)
# Go here to choose other colors: http://colorbrewer2.org/  # of classes=6, sequential, rgb
scl = [[0.0, 'rgb(241,238,246)'],[0.2, 'rgb(212,185,218)'],[0.4, 'rgb(201,148,199)'],\
            [0.6, 'rgb(223,101,176)'],[0.8, 'rgb(221,28,119)'],[1.0, 'rgb(152,0,67)']]

df['text'] = "Defect %"

data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df['STATECD'],
        z = df['VALUE'].astype(float),  # Ensure it is a numeric type
        locationmode = 'USA-states',
        text = df['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',  # white lines
                width = 2
            )
        ),
        colorbar = dict(
            title = "Defect %"
        )
    ) ]

layout = dict(
        title = 'Hard Drive Failures',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)',  # white color lakes
        ),
        width=800,
        height=550
    )
   
fig = dict( data=data, layout=layout )

iplot(fig, show_link=False )<jupyter_output><empty_output><jupyter_text>Make this into a function<jupyter_code>def state_choropleth(df, title='State Choropleth'):
    """df = dataframe, title=your desired title"""
    
    # Go here to choose other colors: http://colorbrewer2.org/  # of classes=6, sequential, rgb
    scl = [[0.0, 'rgb(241,238,246)'],[0.2, 'rgb(212,185,218)'],[0.4, 'rgb(201,148,199)'],\
                [0.6, 'rgb(223,101,176)'],[0.8, 'rgb(221,28,119)'],[1.0, 'rgb(152,0,67)']]

    df['text'] = "Defect %"

    data = [ dict(
            type='choropleth',
            colorscale = scl,
            autocolorscale = False,
            locations = df['STATECD'],
            z = df['VALUE'].astype(float),  # Ensure it is a numeric type
            locationmode = 'USA-states',
            text = df['text'],
            marker = dict(
                line = dict (
                    color = 'rgb(255,255,255)',  # white lines
                    width = 2
                )
            ),
            colorbar = dict(
                title = "Defect %"
            )
        ) ]

    layout = dict(
            title = 'Hard Drive Failures',
            geo = dict(
                scope='usa',
                projection=dict( type='albers usa' ),
                showlakes = True,
                lakecolor = 'rgb(255, 255, 255)',  # white color lakes
            ),
            width=800,
            height=550
        )
       
    fig = dict( data=data, layout=layout )

    iplot(fig, show_link=False )
df = pd.read_clipboard()
df.VALUE = df.VALUE.str.replace('%','')

state_choropleth(df, 'Hard Drive Failures')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15331944030961595, 'fraction_numerical': 0.05358737719559393, 'mean_word_length': 2.1788079470198674, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '395808', 'license': 'MIT', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1116, 'n_words': 224, 'path': 'jupyter_notebooks/plotly/States_Choropleth_Example.ipynb', 'repo_name': 'manual123/Nacho-Jupyter-Notebooks', 'size': '3359'}