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
#1
Hi,

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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  concat 3 columns of dataframe to one column flash77 2 778 Oct-03-2023, 09:29 PM
Last Post: flash77
  HTML Decoder pandas dataframe column mbrown009 3 962 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  attempt to split values from within a dataframe column mbrown009 8 2,223 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  New Dataframe Column Based on Several Conditions nb1214 1 1,783 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Putting column name to dataframe, can't work. jonah88888 1 1,804 Sep-28-2021, 07:45 PM
Last Post: deanhystad
  Remove specific values from dataframe jonah88888 0 1,688 Sep-24-2021, 05:09 AM
Last Post: jonah88888
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,239 May-17-2021, 07:02 AM
Last Post: lorensa74
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 2,918 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  How to search for specific string in Pandas dataframe Coding_Jam 1 2,415 Nov-02-2020, 09:35 AM
Last Post: PsyPy
  merging dataframe into another on a specific row danlin123 0 1,436 Sep-23-2020, 02:42 PM
Last Post: danlin123

Forum Jump:

User Panel Messages

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