-2

Anyone can help me understand why Inflation appears in the first column and not second and how to change that? I tried different methods and none seems to work. Thank you!

Screenshot

I tried using loc but the output was the same.

Beata
  • 1
  • 1
  • Please [don't post images of code/error/textual content](https://meta.stackoverflow.com/q/285551). Paste them here as text. – InSync Aug 21 '23 at 16:18
  • I'm not going to type your program out to write an answer but looking at the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html#pandas-dataframe), you set data plus index when creating the dataframe. Stick monthly_inflation in the data dictionary instead. And post text because images of code are just rude. – tdelaney Aug 21 '23 at 16:23
  • That's not a good dup. A dozen mostly irrelevant answers when really the problem is that the inflation Series was used as an index when creating the dataframe. – tdelaney Aug 21 '23 at 16:50

1 Answers1

0

To reorder a DataFrame, use:

inflation_table = inflation_table.reindex(columns=['Year', 'Inflation'])
5px
  • 131
  • 9