python-不可损坏类型:';系列';在熊猫中使用数据帧。查询
发布时间:2022-08-22 19:31:18 349
相关标签: # node.js
df_dict
字典描述如下。我收到的错误是不可损坏类型:“系列”
据我所知,当你的字典没有列表或任何东西时,就会发生这种错误。我第一次用一个键测试它,但我得到了同样的错误。我遇到了路障,不知道如何解决这个问题。
这是我的预处理方法
def preprocess(df_dict, remove_rows, keep_rows):
for key, df in df_dict.items():
print(key)
initial_count = len(df_dict[key])
df_dict[key] = (
df
# Make everything lower case
.assign(Text=lambda x: x['Text'].str.lower())
# Keep the rows that mention name
.query(f'Text.str.contains("{keep_rows[key]}")')
# Remove the rows that mentioned the other three people.
.query(f'~Text.str.contains("{remove_rows[key]}")')
# Remove all the URLs
.assign(Text=lambda x:x['Text'].apply(lambda s: re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', s)))
)
final_count = len(df_dict[key])
print("%d tweets kept out of %d" % (final_count, initial_count))
return df_dict
这是我用来调用预处理方法的代码
df_dict = {
'johnny depp': johnny_data,
"amber heard": amber_data
}
remove_rows = {
'johnny depp': 'amber|heard|camila|vasquez|shannon|curry',
"amber heard": 'johnny|depp|camila|vasquez|shannon|curry'
}
keep_rows = {
'johnny depp': 'johnny|depp',
"amber heard": 'amber|heard'
}
df_test_data = preprocess(df_dict, remove_rows, keep_rows)
我希望我已经在这个论坛上澄清了我的问题,因为这是我在这里的第一篇帖子,所以我也希望我遵守了所有关于发帖的常规协议。
我正在附加收到的错误消息:代码错误 Error part 1 Error part 2
代码链接如下:协作链接
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报