0

I would like to retrieve data from a dataframe with the iloc function. For ex. df.iloc[5:,1] but i want to set the line number to reach with an external variable. I tried to set from_val = '5:' and df.iloc[from_val,1] but it's not working. I've a error of : "ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types"

How to perform ? Best regards

CedM
  • 91
  • 1
  • 8
  • The error message seems self-explanatory, and your two code examples clearly have a crucial difference, which, again, should be easy to figure out from the error. Can you be more specific about which part is the issue? – AMC Jan 22 '20 at 00:11
  • Does this answer your question? [Proper way to use iloc in Pandas](https://stackoverflow.com/questions/42139624/proper-way-to-use-iloc-in-pandas) – AMC Jan 22 '20 at 00:12

1 Answers1

2

Try:

from_val = 5
 df.iloc[from_val:,1] 

Alternatively:

from_val="5:"
eval(f"df.iloc[{from_val}, 1]")
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34