我想写一个程序,它搜索一个数据框,如果其中任何一项超过50个字符长,打印行号,并询问是否要继续搜索数据框。
threshold = 50
mask = (df.drop(columns=exclude, errors='ignore')
.apply(lambda s: s.str.len().ge(threshold))
)
out = df.loc[~mask.any(axis=1)]
我尝试使用此方法,但我不想删除行,只打印字符串超过50的行号
输入:
0 "Robert","20221019161921","London"
1 "Edward","20221019161921","London"
2 "Johnny","20221019161921","London"
3 "Insane string which is way too longggggggggggg","20221019161921","London"
输出量:
Row 3 is above the 50-character limit.
我还希望程序打印特定的值或字符串,这是太长。
1条答案
按热度按时间d7v8vwbk1#
您可以用途:
输出量:
中间体
s
: