Home > Back-end >  Unable to correct "TypeError: 'int' object is not iterable"
Unable to correct "TypeError: 'int' object is not iterable"

Time:01-15

having python code: ....

def DisplayTable(filename):
    #dir = os.path.dirname(__file__)
    fullFilename = dir '/Data/' str(filename)
    data = pd.read_csv(fullFilename, header=None)
    data=data.iloc[:: -1]
    print(data)
    stringList = [str(x) for x in data] 
    print(stringList)
    #data= tuple(data)
    headings=(" ", "Date", " ", "Temps")
    return render_template('fDetailTemps.html',  data=data, headings=headings)`

My HTML gives the error: TypeError: 'int' object is not iterable

I have tried several solutions found on this board, but none have helped (latest trial is in above code using str(x).) the print(data) statement gives:

4    Date:   2021-Dec-20, 04:00       Kombucha Temp:   77.56
3    Date:   2021-Dec-20, 03:00       Kombucha Temp:   77.79
2    Date:   2021-Dec-20, 02:00       Kombucha Temp:   77.79
1    Date:   2021-Dec-20, 01:00       Kombucha Temp:   77.90
0    Date:   2021-Dec-20, 00:00       Kombucha Temp:   77.79

and the print(string_list) gives:

['0', '1', '2', '3']

portion of the HTML code:

       <table>
        <tr>
           {% for header in headings %}
              <th>{{ header }} </th>
           {% endfor %}
        </tr>
        {% for row in data %}
           <tr>
               {% for cell in row %}
                  <td> {{ cell }} </td>
               {% endfor %}
           </tr>
        {% endfor %}
        </table>

CodePudding user response:

Remove for cell in row inside of your HTML.

for row in data makes row the integer 0 or 1 or 2...etc and because of that for cell in row makes no sense as row is an integer not a list to iterate over.

  •  Tags:  
  • Related