-1

I am trying to create a plot for a large data set of around 50,000 rows, where I am trying to plot a series for a single column of the data, but instead of using the unique row data values, it is using the index values ranging from 0 - 50,000 as x values. Is there any way I can somehow swap the x and y axis values?

The data being used is the PUMS household languages data

Here is a screenshot of the code and output of the plot in question:

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • **[Don't Post Screenshots](https://meta.stackoverflow.com/questions/303812/)**. This question needs a [SSCCE](http://sscce.org/). **Always** provide a [mre], with **code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. It's likely the question will be down-voted and closed. You're discouraging assistance, as no one wants to retype data/code, and screenshots are often illegible. [edit] the question and **add text**. Plots are okay. See [How to provide a reproducible dataframe](https://stackoverflow.com/questions/52413246) – Trenton McKinney Jun 05 '23 at 16:41
  • What do you expect to happen with a line plot? You probably need a bar plot of the value_counts. `langData.value_counts().plot(kind='bar')` – Trenton McKinney Jun 05 '23 at 16:43

1 Answers1

0

You want to plot the actual values of series on x-axis, not its index. So here is the simple code to do so:

name = langData.name  # save the name of the column/series
langData = langData.reset_index()  # convert series to dataframe
langData = langData.set_index(name)  # set the values as series index
langData.plot()
Kyle F Hartzenberg
  • 2,567
  • 3
  • 6
  • 24