I have a Dataframe with text in every cell. I want to iterate over the dataframe and the single characters of its cells and fill a list with either 0 for having a whitespace or 1 for having a character. I tried itertuples, iterrows and iteritems, but for all I can't access every single character of a string.
crispr = pd.DataFrame({'Name': ['Bob', 'Jane', 'Alice'],
'Issue': ['Handling data', 'Could not read sample', 'No clue'],
'Comment': ['Need to revise data', 'sample preparation', 'could not find out where problem occurs']})
what I tried is:
dflist = []
countchar= 0
for i,j in crispr.iteritems():
for x in range(len(j)):
test = j[countchar].isspace()
countchar+=1
if test == True:
dflist.append(0)
else:
dflist.append(1)
I tried to figure out if it would work with itertuples or iterrows():
for i in crispr.itertuples():
for j in i:
for b in j:
print(b)
It occurs the following error:
TypeError: 'int' object is not iterable
Expected output is a list containing 1 for a character and 0 for whitespace:
dflist = [[1,1,1], [1,1,1,1], [1,1,1,1,1]],[[1,1,1,1,1,1,1,0,1,1,1,1], ...]]