Python Forum
Negative indexing/selecting working and not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Negative indexing/selecting working and not working
#6
I don't understand your question. Inside the function perc is a series. It is going to look like this:
type_code
-2     0.746501  <- This is perc[-2]
-1     9.144635
 0    18.475894
 1    59.937792  <- This is not perc[-2]
 2    11.695179
It makes one of these for each group (question).

perc does not exist outside the function. You cannot call the function unless you make the groups (you will have duplicate labels in the row index).

Can you post the code that makes a list named "perc" that contains 40 elements. is it something like this?
perc = source["percentage"]
print(perc[-2])
This would raise a key error because the row indices are 0, 1...39. -2 is not a valid index.
If you want a list of the values, ask for that.
perc = source["percentage"].values  # Returns a list of values from the "percentage" column.
print(perc[-2])
Reply


Messages In This Thread
RE: Negative indexing/selecting working and not working - by deanhystad - Jul-12-2023, 05:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyperclip stopped working OAP 8 971 Apr-13-2025, 12:54 PM
Last Post: OAP
  Appending sys.path not working with spyder Larz60+ 2 492 Apr-11-2025, 08:50 AM
Last Post: Larz60+
  code isnt working. nezercat33 1 656 Mar-14-2025, 03:45 AM
Last Post: deanhystad
  Simple code not working properly tmv 2 510 Feb-28-2025, 09:27 PM
Last Post: deanhystad
  I'm new to Python - can someone help with this code as it is not working? lminc123 1 535 Feb-13-2025, 06:13 PM
Last Post: lminc123
  Python-Kasa stopped working liderbug 1 467 Jan-27-2025, 02:47 PM
Last Post: liderbug
  working with pivot table gunther 1 410 Jan-22-2025, 08:55 AM
Last Post: Keville_35
  Matplotlib not working svalencic 4 917 Dec-18-2024, 11:10 AM
Last Post: svalencic
  my code is not working erTurko 1 657 Nov-11-2024, 08:43 AM
Last Post: buran
  List comprehension not working right Cris9855 3 952 Nov-04-2024, 03:46 PM
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