0

I have data from facebook that I parsed through and I want to make a plot using MatPlotLib. I want to see how often I use certain words per year in a line graph. I have this data that I want to look like the figure below but plotted with MatPlotLib instead of Altair. (Don't worry about the titles or legends)

The data below can be turned into a DataFrame using pandas - pd.DataFrame(df)

df =  {'word': {2: 'lol',
  3: 'like',
  4: 'yeah',
  5: 'get',
  6: 'know',
  7: 'good',
  8: 'ur',
  9: 'ok',
  10: 'haha',
  11: 'man',
  12: 'lol',
  13: 'yeah',
  14: 'like',
  15: 'good',
  16: 'ok',
  17: 'ur',
  18: 'man',
  19: 'get',
  20: 'know',
  21: 'haha',
  22: 'yeah',
  23: 'lol',
  24: 'man',
  25: 'ok',
  26: 'like',
  27: 'good',
  28: 'get',
  29: 'ur',
  30: 'know',
  31: 'haha'},
 'count': {2: 9,
  3: 5,
  4: 5,
  5: 4,
  6: 3,
  7: 3,
  8: 2,
  9: 1,
  10: 1,
  11: 1,
  12: 57,
  13: 48,
  14: 36,
  15: 31,
  16: 23,
  17: 19,
  18: 17,
  19: 16,
  20: 11,
  21: 2,
  22: 129,
  23: 100,
  24: 52,
  25: 51,
  26: 50,
  27: 40,
  28: 35,
  29: 30,
  30: 27,
  31: 22},
 'year': {2: 2010,
  3: 2010,
  4: 2010,
  5: 2010,
  6: 2010,
  7: 2010,
  8: 2010,
  9: 2010,
  10: 2010,
  11: 2010,
  12: 2011,
  13: 2011,
  14: 2011,
  15: 2011,
  16: 2011,
  17: 2011,
  18: 2011,
  19: 2011,
  20: 2011,
  21: 2011,
  22: 2012,
  23: 2012,
  24: 2012,
  25: 2012,
  26: 2012,
  27: 2012,
  28: 2012,
  29: 2012,
  30: 2012,
  31: 2012}}

enter image description here

1 Answer 1

2

You want to pivot the table and plot:

# convert to dataframe
df = pd.DataFrame(df)

df.pivot(index='year',columns='word',values='count').plot()

Output:

enter image description here

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.