Python Forum
Unexpected output from df.loc when indexing by label
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected output from df.loc when indexing by label
#2
There is some weird multi-indexing thing going on with 2013.

If you look at the list of index values you'll see that 2013 is suspiciously absent even though it appears in the dataframe when printed.
Output:
Index(['2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', 'Career', '7 yrs', '2 yrs', '1 yr'], dtype='object') Year Age Tm Pos No. G GS Pnt Yds Y/P RetYds Net NY/P Lng TB TB% In20 In20% Blck AV 2013 23 DET P 6 16 0 72 3399 47.2 250 2949 41.0 72 10 13.9% 22 30.6% 1 3 2014 24 DET P 6.0 16 0.0 68 3138 46.1 311 2727 40.1 71 5 7.4% 29 42.6% 0 3 2015 25 DET P 6.0 16 0.0 80 3679 46.0 263 3356 42.0 66 3 3.8% 25 31.3% 0 3 . . .
Then printed a row.
Output:
df.loc['2017'] Year 2013 Age 23 27 Tm DET DET Pos P P
This series has 2 rows. The year, and 2013. If I print the '2022' row I see the same thing. The 2022 year values and the 2013 values.
Output:
df.loc['2022'] Year 2013 Age 23 32 Tm DET BUF Pos P P
Why this is happening is beyond my scope. I looked at the web page, but it is too complicated for me to understand how the tables are created and why they are messing up the dataframe
idratherbecoding likes this post
Reply


Messages In This Thread
RE: Unexpected output from df.loc when indexing by label - by deanhystad - Apr-18-2023, 01:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output Starter 2 577 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 839 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 589 Oct-24-2023, 05:56 AM
Last Post: buran
  unexpected output asyrafcc99 0 1,538 Oct-24-2020, 02:40 PM
Last Post: asyrafcc99
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,106 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  How to change 0 based indexing to 1 based indexing in python..?? Ruthra 2 4,593 Jan-22-2020, 05:13 PM
Last Post: Ruthra
  Unexpected output palladium 4 2,846 Jan-11-2020, 03:26 PM
Last Post: palladium
  Unexpected output: if statement CabbageMan 1 1,822 Sep-04-2019, 04:12 PM
Last Post: ThomasL
  Unexpected Output using classes and inheritance langley 2 2,014 Jul-04-2019, 09:33 AM
Last Post: langley
  float multiplication - unexpected output inesk 3 3,423 Dec-11-2018, 10:59 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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