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
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,173 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,626 Aug-26-2024, 04:52 PM
Last Post: Calab
  Create new column in dataframe Scott 10 3,573 Jun-30-2024, 10:18 PM
Last Post: Scott
  attempt to split values from within a dataframe column mbrown009 9 5,926 Jun-20-2024, 07:59 PM
Last Post: AdamHensley
  Putting column name to dataframe, can't work. jonah88888 2 3,265 Jun-18-2024, 09:19 PM
Last Post: AdamHensley
  concat 3 columns of dataframe to one column flash77 2 2,128 Oct-03-2023, 09:29 PM
Last Post: flash77
  HTML Decoder pandas dataframe column mbrown009 3 2,683 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  New Dataframe Column Based on Several Conditions nb1214 1 2,518 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Remove specific values from dataframe jonah88888 0 2,254 Sep-24-2021, 05:09 AM
Last Post: jonah88888
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 3,006 May-17-2021, 07:02 AM
Last Post: lorensa74

Forum Jump:

User Panel Messages

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