我已经定义了以下辅助方法
def load_excel(file_path: str, sheet_name: str = ''):
if sheet_name == '':
df = pd.read_excel(file_path).fillna('').apply(lambda x: x.astype(str).str.lower())
else:
df = pd.read_excel(file_path, sheet_name).fillna('').apply(lambda x: x.astype(str).str.lower())
return df
def build_score_dict(keywords_df: pd.DataFrame, tokens: list):
"""
Returns a tuple of two dictionories. i.e. tuple[dict, dict]
"""
matched_keywords_by_cat_dict={}
score_dict={}
cnt_cols = keywords_df.shape[1]
for col_idx in range(0, cnt_cols):
keyword_list=list(keywords_df.iloc[:,col_idx])
matched_keywords=[]
parent_cat=0
for j in range(0,len(tokens)):
token = tokens[j]
if token in keyword_list:
parent_cat= parent_cat + 1
matched_keywords.append(token)
parent_cat_name = keywords_df.columns[col_idx]
matched_keywords_by_cat_dict[parent_cat_name]=matched_keywords
score_dict[parent_cat_name]=parent_cat
return matched_keywords_by_cat_dict, score_dict
我的电话build_score_dict
,如下图
third_level_closing=load_excel(input_dir+'third_level_keywords.xlsx',sheet_name='closing')
_, level3_score_dict = build_score_dict(third_level_closing, tokens)
Pylance 在 VSCode 中给我以下警告/错误。这里发生了什么以及如何解决它?
Argument of type "Series[Dtype]" cannot be assigned to parameter "keywords_df" of type "DataFrame" in function "build_score_dict"
"Series[Dtype]" is incompatible with "DataFrame"Pylance (reportGeneralTypeIssues)