<jupyter_start><jupyter_text>Fig 1<jupyter_code>df = pd.read_excel("raw/figures.xlsx",sheet_name='Fig1',skiprows=6).dropna().replace('-',0)
df=df.set_index('Unnamed: 0').stack().reset_index()
df.columns=['income','category','value']
df['value']/=100
f = "fig1_income"
f1 = eco_git_path + f + ".csv"
df.to_csv("data/" + f + ".csv")
f += local_suffix
open("visualisation/" + f + ".html", "w").write(
    vega_embed.replace(
        "JSON_PATH", f1.replace("/data/", "/visualisation/").replace(".csv", ".json")
    )
)
if LOCAL:
    f1 = df
readme="### "+f+'\n!["'+f+'"](visualisation/'+f+'.png "'+f+'")\n\n'
df.head()
base = (
    alt.Chart(f1)
    .encode(tooltip="tooltip:N")
    .transform_calculate(tooltip="datum.income+' 🏢 '+datum.category+' 📈 '+round(datum.value*100)+'%'")
).transform_calculate(x="round(datum.value*100)")
bars1 = base.mark_bar(height=15, opacity=0.9, color=colors["eco-turquiose"]).encode(
    x=alt.X(
        "value:Q",
        stack="zero",
        axis=alt.Axis(
            grid=False,
            title="",
            labelColor=colors["eco-gray"],
            titleColor=colors["eco-gray"],
            tickColor=colors["eco-gray"],
            domainColor=colors["eco-gray"],
            format=".0%",
            tickCount=10,
            orient="bottom",
            labelAngle=0,
        ),
        scale=alt.Scale(
            domain=[0,1]
        )
    ),
    order="income:N",
    y=alt.Y(
        "income:N",
        sort=[],
        axis=alt.Axis(
            grid=False,
            title="% by income band",
            titleX=0,
            titleY=-5,
            titleBaseline="bottom",
            titleAngle=0,
            titleAlign="left",
            labelColor=colors["eco-gray"],
            titleColor=colors["eco-gray"],
            tickColor=colors["eco-gray"],
            domainColor=colors["eco-gray"],
        ),
    ),
    color=alt.Color(
        "category:N",
        legend=alt.Legend(title="",labelLimit=400),
        sort=[],
        scale=alt.Scale(
            range=[colors["eco-mid-blue"],colors["eco-turquiose"],
                    colors["eco-red"], colors["eco-gray"]],
        ),
    ),
)
text1 = bars1.mark_text(dx=-2, dy=1, align="right").encode(
    text=alt.Text("x:Q", format=".0f"),
    x=alt.X("value:Q", stack="zero"),
    order="income:N",
    color=alt.condition(
        datum.value < 0.04,
        alt.ColorValue(None),
        alt.ColorValue("white"),
    ),
)
layer1 = (
    ((bars1 + text1).properties(height=alt.Step(20), width=200))
    .configure_view(stroke=None)
    .properties(title="")
)
layer1.save("visualisation/" + f + ".json")
layer1.save("visualisation/" + f + ".png")
open("README.md",'w').write(readme)
layer1<jupyter_output>WARN Channel order is inappropriate for nominal field, which has no inherent order.
WARN Channel order is inappropriate for nominal field, which has no inherent order.
Fontconfig error: Cannot load default config file<jupyter_text>Fig 2<jupyter_code>df = pd.read_excel("raw/figures.xlsx",sheet_name='Fig2_Fig3',skiprows=2,usecols='B:F',nrows=10)
df=df.set_index(df.columns[0]).stack().reset_index()
df.columns=['advantage','age','value']
df['value']/=100
df=df[::-1]
f = "fig2_advantages"
f2 = eco_git_path + f + ".csv"
df.to_csv("data/" + f + ".csv")
f += local_suffix
open("visualisation/" + f + ".html", "w").write(
    vega_embed.replace(
        "JSON_PATH", f2.replace("/data/", "/visualisation/").replace(".csv", ".json")
    )
)
if LOCAL:
    f2 = df
readme="### "+f+'\n!["'+f+'"](visualisation/'+f+'.png "'+f+'")\n\n'
df.head()
bars = alt.Chart(f2).encode(
    x=alt.X(
        "value:Q",
        stack=False,
        title="",
        axis=alt.Axis(
            grid=False,
            title="",
            titleAnchor="end",
            titleX=415,
            titleY=7,
            format='.0%',
            labelColor=colors["eco-gray"],
            titleColor=colors["eco-gray"],
            tickColor=colors["eco-gray"],
            domainColor=colors["eco-gray"],
        ),
    ),
    y=alt.Y("advantage:N", title="", axis=None, sort=[]),
    tooltip="tooltip:N"
).transform_calculate(tooltip="datum.advantage+' 🏢 '+datum.age+' 📈 '+round(datum.value*100)+'%'")

bars1 = bars.mark_bar(
    size=11, yOffset=-14, color=colors["eco-turquiose"], opacity=0.8
).transform_filter("datum.age=='16-29'")
bars2 = bars.mark_bar(
    size=11, yOffset=-26, color=colors["eco-green"], opacity=0.8
).transform_filter("datum.age=='Overall'")
bars3 = bars.mark_bar(
    size=11, yOffset=-2, color=colors["eco-light-blue"], opacity=0.8
).transform_filter("datum.age=='30-49'")
bars4 = bars.mark_bar(
    size=11, yOffset=10, color=colors["eco-mid-blue"], opacity=0.8
).transform_filter("datum.age=='50-69'")
labels1 = bars1.mark_text(
    align="left",
    xOffset=5,
    yOffset=-14,
    color=colors["eco-turquiose"],
).encode(text=alt.Text("value:N",format='.0%'))
labels2 = bars2.mark_text(
    align="left",
    xOffset=5,
    yOffset=-26,
    color=colors["eco-green"],
).encode(text=alt.Text("value:N",format='.0%'))
labels3 = bars3.mark_text(
    align="left",
    xOffset=5,
    yOffset=-2,
    color=colors["eco-light-blue"],
).encode(text=alt.Text("value:N",format='.0%'))
labels4 = bars4.mark_text(
    align="left",
    xOffset=5,
    yOffset=10,
    color=colors["eco-mid-blue"],
).encode(text=alt.Text("value:N",format='.0%'))
titles = (
    bars.mark_text(
        align="left", size=11, baseline="bottom", yOffset=-35, color=colors["eco-gray"]
    )
    .encode(text="advantage:N", x=alt.X("x0:Q",axis=alt.Axis(format='.0%')), y=alt.Y("advantage:N",sort=[]))
    .transform_filter("datum.age=='Overall'")
    .transform_calculate(x0="0")
)
legendkey='Fewer distractions'
legendx=0.7
legendfs=11
legend1 = (
    bars1.mark_text(align="right", size=legendfs, yOffset=-14, color=colors["eco-turquiose"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend2 = (
    bars2.mark_text(align="right", size=legendfs, yOffset=-27, color=colors["eco-green"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend3 = (
    bars3.mark_text(align="right", size=legendfs, yOffset=0, color=colors["eco-light-blue"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend4 = (
    bars4.mark_text(align="right", size=legendfs, yOffset=13, color=colors["eco-mid-blue"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)

layer = (
    (
        (bars1 + legend1)
        + (bars2 + legend2)
        + (bars3 + legend3)
        + (bars4 + legend4)
        + labels1
        + labels2
        + labels3
        + labels4
        + titles
    )
    .configure_view(stroke=None)
    .properties(title="")
    .properties(height=alt.Step(75), width=400)
)
layer.save("visualisation/" + f + ".json")
layer.save("visualisation/" + f + ".png")
open("README.md",'a').write(readme)
layer<jupyter_output>Fontconfig error: Cannot load default config file<jupyter_text>Fig 3<jupyter_code>df = pd.read_excel("raw/figures.xlsx",sheet_name='Fig2_Fig3',skiprows=15,usecols='B:F',nrows=10)
df=df.set_index(df.columns[0]).stack().reset_index()
df.columns=['advantage','age','value']
df['value']/=100
df=df[::-1]
f = "fig3_disadvantages"
f3 = eco_git_path + f + ".csv"
df.to_csv("data/" + f + ".csv")
f += local_suffix
open("visualisation/" + f + ".html", "w").write(
    vega_embed.replace(
        "JSON_PATH", f3.replace("/data/", "/visualisation/").replace(".csv", ".json")
    )
)
if LOCAL:
    f3 = df
readme="### "+f+'\n!["'+f+'"](visualisation/'+f+'.png "'+f+'")\n\n'
df.head()
bars = alt.Chart(f3).encode(
    x=alt.X(
        "value:Q",
        stack=False,
        title="",
        axis=alt.Axis(
            grid=False,
            title="",
            titleAnchor="end",
            titleX=415,
            titleY=7,
            format='.0%',
            labelColor=colors["eco-gray"],
            titleColor=colors["eco-gray"],
            tickColor=colors["eco-gray"],
            domainColor=colors["eco-gray"],
        ),
    ),
    y=alt.Y("advantage:N", title="", axis=None, sort=[]),
    tooltip="tooltip:N"
).transform_calculate(tooltip="datum.advantage+' 🏢 '+datum.age+' 📈 '+round(datum.value*100)+'%'")

bars1 = bars.mark_bar(
    size=11, yOffset=-14, color=colors["eco-turquiose"], opacity=0.8
).transform_filter("datum.age=='16-29'")
bars2 = bars.mark_bar(
    size=11, yOffset=-26, color=colors["eco-green"], opacity=0.8
).transform_filter("datum.age=='Overall'")
bars3 = bars.mark_bar(
    size=11, yOffset=-2, color=colors["eco-light-blue"], opacity=0.8
).transform_filter("datum.age=='30-49'")
bars4 = bars.mark_bar(
    size=11, yOffset=10, color=colors["eco-mid-blue"], opacity=0.8
).transform_filter("datum.age=='50-69'")
labels1 = bars1.mark_text(
    align="left",
    xOffset=5,
    yOffset=-14,
    color=colors["eco-turquiose"],
).encode(text=alt.Text("value:N",format='.0%'))
labels2 = bars2.mark_text(
    align="left",
    xOffset=5,
    yOffset=-26,
    color=colors["eco-green"],
).encode(text=alt.Text("value:N",format='.0%'))
labels3 = bars3.mark_text(
    align="left",
    xOffset=5,
    yOffset=-2,
    color=colors["eco-light-blue"],
).encode(text=alt.Text("value:N",format='.0%'))
labels4 = bars4.mark_text(
    align="left",
    xOffset=5,
    yOffset=10,
    color=colors["eco-mid-blue"],
).encode(text=alt.Text("value:N",format='.0%'))
titles = (
    bars.mark_text(
        align="left", size=11, baseline="bottom", yOffset=-35, color=colors["eco-gray"]
    )
    .encode(text="advantage:N", x=alt.X("x0:Q",axis=alt.Axis(format='.0%')), y=alt.Y("advantage:N",sort=[]))
    .transform_filter("datum.age=='Overall'")
    .transform_calculate(x0="0")
)
legendkey='More distractions'
legendx=0.58
legendfs=11
legend1 = (
    bars1.mark_text(align="right", size=legendfs, yOffset=-14, color=colors["eco-turquiose"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend2 = (
    bars2.mark_text(align="right", size=legendfs, yOffset=-27, color=colors["eco-green"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend3 = (
    bars3.mark_text(align="right", size=legendfs, yOffset=0, color=colors["eco-light-blue"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)
legend4 = (
    bars4.mark_text(align="right", size=legendfs, yOffset=13, color=colors["eco-mid-blue"])
    .encode(text="age:N", x="x0:Q")
    .transform_filter("datum.advantage=='"+legendkey+"'")
    .transform_calculate(x0=str(legendx))
)

layer = (
    (
        (bars1 + legend1)
        + (bars2 + legend2)
        + (bars3 + legend3)
        + (bars4 + legend4)
        + labels1
        + labels2
        + labels3
        + labels4
        + titles
    )
    .configure_view(stroke=None)
    .properties(title="")
    .properties(height=alt.Step(75), width=400)
)
layer.save("visualisation/" + f + ".json")
layer.save("visualisation/" + f + ".png")
open("README.md",'a').write(readme)
layer<jupyter_output>Fontconfig error: Cannot load default config file
{'fraction_non_alphanumeric': 0.210622233793283, 'fraction_numerical': 0.028898724290549335, 'mean_word_length': 3.498048399687744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '600260', 'license': 'MIT', 'n_tokens_mistral': 4512, 'n_tokens_neox': 4296, 'n_words': 556, 'path': 'articles/2021-07-21-will-people-go-back-to-the-office-after-the-pandemic/parser.ipynb', 'repo_name': 'EconomicsObservatory/ECOvisualisations', 'size': '11523'}