Home > Mobile >  Getting the xlabels to reflect the DataFrame column
Getting the xlabels to reflect the DataFrame column

Time:02-26

I have the attached DF that I am trying to plot however, the xvalues are the index from the DF when I would want them to be the actual episode names. Any recommendations here?DF pic

CodePudding user response:

By first selecting the column from the DataFrame, and the plotting that you end up not "carrying over" those labels with you. You fix this two different ways:

  1. plot from the DataFrame, not from the Series
top_episodes.plot(x="EpisodeTitle", y="Viewship(MM)", kind="bar")
  1. Alternatively, set the index to be the EpisodeTitle, and then perform your column selection/plotting.
top_episodes.set_index("EpisodeTitle")["Viewship(MM)"].plot(kind="bar")
  • Related