• Status: Open
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

How to parameterize the column values for df.iloc

I want to get input from a user in order to pass it as a listlike set of integers for iloc, but cannot get the list into a working form like [1,3,4,5] for example.

df.iloc[:,choices]

In the above code, I want to specify column indexes from user input instead of hard coding the numbers in.  Please advise.
0
dorianit
Asked:
dorianit
2 Comments
 
Marcin KarkochaSenior DevOps Engineer (Nokia)Commented:
Can you precise your question? Is about DataFrames from Pandas or something?
0
 
dorianitAuthor Commented:
I want to take input and pass it to the df.iloc column values.  I found a solution wit the code below.  The requirement is that user separate their values with a space, which is okay for me.

chosenfields = [int(x) for x in input("\nPlease choose the fields  (space separated) (example: 0 2 15).  ").split()]
0

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now