Python Forum
Setting the x-axis to a specific column in a dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting the x-axis to a specific column in a dataframe

I am trying to update the x-axis on a line chart that contains two y-axes. The data is being read from two separate Excel files and the column that I want to use as the x-axis is in both Excel files and formatted the same ("Years" 1985-2021), however when I plot it, the x-axis starts at 0 and goes from there.

I've tried using the set_index() function but still got the Excel row numbers as the x-axis.

Here's the code (apologies if this isn't formatted correctly); Excel files are attached.

end = pd.read_excel('test_END.xlsx')
start = pd.read_excel('test_START.xlsx')

end["End"].plot(figsize=(20, 10));
start["Start"].plot(secondary_y=True, style="orange");

Any help would be greatly appreciated – thanks!

Attached Files

.xlsx   test_END.xlsx (Size: 10.54 KB / Downloads: 0)
.xlsx   test_START.xlsx (Size: 20.35 KB / Downloads: 0)

Possibly Related Threads…
Thread Author Replies Views Last Post
  New Dataframe Column Based on Several Conditions nb1214 1 189 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Putting column name to dataframe, can't work. jonah88888 1 390 Sep-28-2021, 07:45 PM
Last Post: deanhystad
  Remove specific values from dataframe jonah88888 0 337 Sep-24-2021, 05:09 AM
Last Post: jonah88888
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 834 May-17-2021, 07:02 AM
Last Post: lorensa74
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 1,096 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  How to search for specific string in Pandas dataframe Coding_Jam 1 1,131 Nov-02-2020, 09:35 AM
Last Post: PsyPy
  merging dataframe into another on a specific row danlin123 0 616 Sep-23-2020, 02:42 PM
Last Post: danlin123
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 2,561 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  Pandas DataFrame and unmatched column sritsv19 0 1,553 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Assigning Column nunique values to another DataFrame column Pythonito 0 784 Jun-25-2020, 05:04 PM
Last Post: Pythonito

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020