Python 有条件地提取数据帧行时,列表索引超出范围
提取部分令牌数据帧会抛出列表索引超出范围错误 编辑以显示完整代码Python 有条件地提取数据帧行时,列表索引超出范围,python,pandas,Python,Pandas,提取部分令牌数据帧会抛出列表索引超出范围错误 编辑以显示完整代码 tokens['len'] = tokens['token_raw'].apply(lambda x: len(x)) txt = "this is a sample text" input_df = pd.DataFrame(txt.lower().split(), columns=['input_text']) input_df = input_df['input_text'].apply(lambda x: flag_non
tokens['len'] = tokens['token_raw'].apply(lambda x: len(x))
txt = "this is a sample text"
input_df = pd.DataFrame(txt.lower().split(), columns=['input_text'])
input_df = input_df['input_text'].apply(lambda x: flag_nonword(x))
def flag_nonword(w):
input_len = len(w)+3
tokens_ext = tokens.loc[tokens['len'] < input_len ]
tokens_ext.sort_values('len',ascending=True, inplace = True)
tokens_ext['ed'] = tokens_ext['token_raw'].apply(lambda x:
nltk.edit_distance(w,x))
tokens_ext.sort_values(by=['ed', 'freq'], ascending=[True, False])
return list(tokens_ext.iloc[:6,0])
tokens['len']=tokens['token_raw'].应用(lambda x:len(x))
txt=“这是一个示例文本”
input_df=pd.DataFrame(txt.lower().split(),columns=['input_text'])
input_df=input_df['input_text']。应用(lambda x:flag_nonword(x))
def标志非文字(w):
输入长度=长度(w)+3
tokens\u ext=tokens.loc[令牌['len']
或两个iloc
s:
def flag_nonword(w):
input_len = len(w)+3
tokens_ext = tokens.loc[tokens['len'] < input_len]
return list(tokens.iloc[:,0].iloc[:6])
def flag_nonword(w):
输入长度=长度(w)+3
tokens\u ext=tokens.loc[令牌['len']
或两个iloc
s:
def flag_nonword(w):
input_len = len(w)+3
tokens_ext = tokens.loc[tokens['len'] < input_len]
return list(tokens.iloc[:,0].iloc[:6])
def flag_nonword(w):
输入长度=长度(w)+3
tokens\u ext=tokens.loc[令牌['len']
你能试试吗
def flag_nonword(w):
input_len = len(w)+3
tokens_ext = tokens.loc[tokens['len'] < input_len + 1]
tokens_ext.sort_values('len',ascending=True, inplace = True)
tokens_ext['ed'] = tokens_ext['token_raw'].apply(lambda x:
def flag_nonword(w):
输入长度=长度(w)+3
tokens\u ext=tokens.loc[令牌['len']
你能试试吗
def flag_nonword(w):
input_len = len(w)+3
tokens_ext = tokens.loc[tokens['len'] < input_len + 1]
tokens_ext.sort_values('len',ascending=True, inplace = True)
tokens_ext['ed'] = tokens_ext['token_raw'].apply(lambda x:
def flag_nonword(w):
输入长度=长度(w)+3
tokens\u ext=tokens.loc[令牌['len']