1

I am trying to loop over a dataframe like the following:

for row, index in split[0].iterrows():
        kitname = row['kit_name'][0]
        print(kitname)

where split is a list of dataframes

split[0] :

  kit_name          kit_info         part_name part_number  
0  KIT0001  Standard FLC Kit  Standard FLC Kit           0   
1  KIT0001  Standard FLC Kit  Standard FLC Kit           0   
2  KIT0001  Standard FLC Kit  Standard FLC Kit           0   

but the following error is coming:

TypeError: 'int' object is not subscriptable

I am using the same code in a different script and it's working fine there

1
  • try print(row['kit_name"], row['kit_name"]) to find the problem. You need to know how to find a look for a problem by yourself, if not you'll take so much time to develop your thing Commented Apr 1, 2022 at 5:57

1 Answer 1

3

Problem is you swap index and row variables, so row are integers so select ['kit_name'] failed:

for row, index in split[0].iterrows():
    kitname = row['kit_name'][0]
    print(kitname)

Need:

for index, row in split[0].iterrows():
    kitname = row['kit_name'][0]
    print(kitname)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.