On my dataframe :
what is the easiest way to browse the datas of my dataframe which are numbers and detect characters of type: ', "and report them ? Can we avoid the series?
CodePudding user response:
You can try:
print('Single quote are detected on row(s): ', df.apply(lambda x: x.astype(str).str.contains("'")).any(axis=1)[lambda x: x].index.tolist())
print('Double quote are detected on row(s): ', df.apply(lambda x: x.astype(str).str.contains('"')).any(axis=1)[lambda x: x].index.tolist())
Output:
Single quote are detected on row(s): ['R2']
Double quote are detected on row(s): ['R1', 'R3']
CodePudding user response:
Try assert
:
x = ''.join(df.astype(str).agg(''.join))
assert not ((':' in x) or ('"' in x)), "Bad characters on a data"