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
  Gmpy2 Newbie Working on Precision charlesrkiss 6 813 Jun-14-2024, 09:53 AM
Last Post: sunflower36002
  Working with group of lines knob 1 321 May-21-2024, 07:21 AM
Last Post: Gribouillis
  two functions working in a strange way zapad 2 393 May-02-2024, 01:35 PM
Last Post: zapad
  Excel isnt working properly after python function is started IchNar 2 447 May-01-2024, 06:43 PM
Last Post: IchNar
  negative memory usage akbarza 1 376 Apr-27-2024, 08:43 AM
Last Post: Gribouillis
  Python trivial endgame engine is not working as expected max22 0 648 Feb-24-2024, 04:41 PM
Last Post: max22
  File Handling not working properly TheLummen 8 1,108 Feb-17-2024, 07:47 PM
Last Post: TheLummen
  Spyder console zoom in not working? Dionysis 2 598 Feb-06-2024, 03:31 PM
Last Post: paul18fr
  SendKeys not working SanjayGMusafir 4 685 Jan-16-2024, 12:07 PM
Last Post: EdwardMatthew
  Text conversion to lowercase is not working ineuw 3 626 Jan-16-2024, 02:42 AM
Last Post: ineuw

Forum Jump:

User Panel Messages

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