Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Created July 31, 2018 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sweemeng/9a19623ae591eed944c2efd7037802c0 to your computer and use it in GitHub Desktop.
Save sweemeng/9a19623ae591eed944c2efd7037802c0 to your computer and use it in GitHub Desktop.
import pandas as pd
import os
def main():
df = pd.read_csv("./bptms_Employed_persons_by_educational_attainment_state-1.csv")
if not os.path.exists("image_dir"):
os.makedirs("image_dir")
for s in df["State/Country"].unique():
plot = draw_chart(df, s)
figure = plot.get_figure()
figure.savefig("image_dir/" + s+".png")
def draw_chart(df, state):
df_state = df[df["State/Country"] == state]
df_year = df_state.pivot(index="Year", columns="Educational attainment", values=" Employed Person ('000) ")
df_year = df_year.convert_objects(convert_numeric=True)
title = "{state} employee in (,000)".format(state=state)
plot = df_year.drop(["Total"],axis=1).plot.area(title=title, )
return plot
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment