0

I have a tkinter program that connects to a CSV file. I am trying to insert certain values from the CSV file into text boxes in tkinter. I am selecting the values using loc slicing.

The problem I am running into is that my slicing returns the column name and index in addition to the value I want. Because of this, I cannot insert the correct value into my tkinter text box. Can someone help me remove the column name and index from my results?

Code:

ID = Entry6.get()
follow_up_DF = pd.read_csv('file.csv')
name = follow_up_DF.loc[follow_up_DF["Email ID"] == int(ID),["Name"]]
subject=Text(home, height=1)
subject.insert(1.0,(name))
subject.place(x=0, y=400)
3
  • Try doing name = follow_up_DF.loc[follow_up_DF["Email ID"] == int(ID),["Name"]].value to simply get the value of the target location. Commented Dec 19, 2022 at 3:14
  • Serialization / IO / conversion. .values - Attributes. to_list() - Conversion. Commented Dec 19, 2022 at 3:32
  • I added "values" to the end of the code and am now getting the correct value returned, however, it is surrounded by brackets. The value returned looks like this [['XXXX']]. Is there any way to only return the string of text? Commented Dec 19, 2022 at 3:34

1 Answer 1

1

Try making name equal to this:

name = follow_up_DF.loc[follow_up_DF["Email ID"] == int(ID),["Name"]].value[0][0]

.value should return just the item from the row, not its index and column name.

Sign up to request clarification or add additional context in comments.

6 Comments

When I used this I got the following error: AttributeError: 'DataFrame' object has no attribute 'item'
try subscripting .values like this --> follow_up_DF.loc[follow_up_DF["Email ID"] == int(ID),["Name"]].values[0]
Thank you - This works in getting rid of one set of brackets, but not the second set or the quotes. Right now I am getting a result like this ['XXXX']
do it again then, ie follow_up_DF.loc[follow_up_DF["Email ID"] == int(ID),["Name"]].values[0][0]
That works perfectly! Thank you for your patience, Python beginner here just getting started :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.