Python Forum
Create selection box to pass string value based on uniques in Excel column
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create selection box to pass string value based on uniques in Excel column
#1
Hello!

New to python but I'm trying, all advice is appreciated.

I have a master data sheet which I have loaded into a data frame. I have then been able to hard-code a value from the "Delivery BA" column in to return a data frame with only that value. I have also been able to list and count the unique values in the column. I currently have a cell which displays a string value of the filter criteria selected for the "Delivery BA" column.

What I would IDEALLY like to do is to be able to prompt the user with a selection box containing all the unique values in the column, and then, upon the user selecting a value, pass that value to the dataframe parameters so that it creates a dataframe with only that "Delivery BA" for entries, preferably without needing to access the value passed in the filter string cell.

I have searched and searched so I apologize if this has been answered already, or something similar.

Please see what little code I have so far.

Explanation of variables:
d: The number of entries in the column "Delivery BA"
g: Not sure what I was doing here; I believe trying to identify the column as "Delivery BA"
h: Entries for a particular company in the column
j: Accessing the cell containing the string value of the selected filter criteria
q: This didn't do what I wanted; I'm not sure now what I wanted
x: Unique values in "Delivery BA" column
y: The number of unique values in "Delivery BA" column. At time of writing, it sits at 739.
    import pandas
    
    data = pandas.read_excel('Test Master.xlsx', header = None).values
    
    print(data)
    df = pandas.DataFrame(data)
    new_header = df.iloc[0]
    df = df[0:]
    df.columns = new_header
    
    d = df['Delivery BA'].value_counts()
    print(d)
    
    g = df.groupby('Delivery BA', as_index = False)
    print(g)
    
    h = df.loc[df['Delivery BA']== 'AmeriGas Propane, L.P.']
    print(h)
    
    j = df.iloc[0, 25]
    print(j)
    
    q = df.loc[df['Delivery BA'] == j]
    
    print(q)
    
    x = df['Delivery BA'].unique()
    print(x)
    y = df['Delivery BA'].nunique()
    print(y)
Apologies if I've posted anything arbitrary or not enough information. Thank you again.
Reply
#2
You can do something like this, add it at the end of the code. If you run python and type d,g,h etc. and enter the select values will be print
def menu():
    choice = input("""What variable do you want to see?
(Choose between: d, g, h, j, q, x and y)

Enter your choice:""")
    if choice == "d":
        print(d)
    elif choice == "g":
        print(g)
    #Etc...
    
menu()
Got some inspiration at this link, maybe its helpfull:http://www.teachingcomputing.com/learn.p..._Functions
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 883 Dec-12-2022, 03:22 AM
Last Post: ill8
  New Dataframe Column Based on Several Conditions nb1214 1 1,800 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 2,686 Jul-28-2021, 11:08 AM
Last Post: jefsummers
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,255 May-17-2021, 07:02 AM
Last Post: lorensa74
  Add column based on others timste 8 4,011 Apr-03-2021, 07:39 AM
Last Post: devesh_sahu
  Extracting rows based on condition on one column Robotguy 2 2,203 Aug-07-2020, 02:27 AM
Last Post: Robotguy
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,278 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 3,048 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature
  Convert dataframe string column to numeric in Python darpInd 1 2,295 Mar-14-2020, 10:07 AM
Last Post: ndc85430
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 2,457 Mar-14-2020, 09:19 AM
Last Post: scidam

Forum Jump:

User Panel Messages

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