I'm trying to, row by row, append any positive numbers to a list until the list has 5 items. Then, for each row searched, place each list within a meta-list holding all of them.
import pandas as pd
import easygui
df_name = easygui.fileopenbox()
thesis_df = pd.ExcelFile(df_name)
df = pd.read_excel(thesis_df)
meta_seq = []
for index, row in df.iterrows():
sequence = []
for item in row[::-1]:
while len(sequence) < 5:
if item.isdigit() == True and item > 0:
sequence.append(item)
else:
continue
sequence = sequence.reverse()
meta_seq.append(sequence)
Currently, when I run the code, I get back an error saying:
AttributeError: 'float' object has no attribute 'isdigit'
答案 0 :(得分:0)
The isdigit
method is supposed to be used with strings, not floats. Try using either
if str(item).isdigit() == True and item > 0:
...
or
if isinstance(item, float) and item > 0:
...