目前我可以这样做:
def my_search_function(text):
return 'x' in text
df = pandas.DataFrame(mydata)
df['search'] = df['text'].apply(lambda text: my_search_function(text))
df[df['search']==True].sort('search', ascending=False)
并获得结果,但我想应该有更好的方法来按功能分组或选择行而不为它创建新列?
更准确地说:
search_num = 111
df['search'] = df['text'].apply(lambda text: list2string(find_number(string2list(text), search_num)))
df[df['search']!=''].sort('search', ascending=False)