python-3.x - AttributeError:“DataFrame”对象没有属性“groupyby”
问题描述
长时间使用 pandas,这是我第一次收到此问题标题所示的错误,我被卡住了,因为我看不出 DataFrame 没有 groupby 功能“可用”的任何原因。 " 已经重新安装了 pandas,甚至查看了正在使用的代码(groupby 在核心模块中定义)。
这就是我正在做的,错误如下所示:
def _bin_by_answer(row):
collocated_answer = row['colname']
if collocated_answer <= -1:
return -1
elif collocated_answer >= 1:
return 1
else:
return 0
df = pd.read_pickle(somepath)
df['binned'] = df.apply(func=lambda row: _bin_by_answer(row), axis=1)
df_sampled = df.groupyby(by='binned', group_keys=False).apply(lambda grp: grp.sample(n=50))
这是错误:
Traceback (most recent call last):
File "/Users/felix/IdeaProjects/cope/ann4class/exportfromaestoretomturk.py", line 858, in <module>
process_and_export_ps2_inductive()
File "/Users/felix/IdeaProjects/cope/ann4class/exportfromaestoretomturk.py", line 786, in process_and_export_ps2_inductive
df_sampled = df_results.groupyby(by=COL_ANSWER1_COLLOCATED_MAJORITY, group_keys=False).apply(
File "/Users/felix/anaconda3/envs/cope/lib/python3.7/site-packages/pandas/core/generic.py", line 5179, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'groupyby'
解决方案
正如 ddoGas 所建议的,这个错误的原因是一个错字。所以,我想一般的答案是:如果你正在阅读这个问题,因为你遇到了类似的问题,请仔细检查你写的函数名是否正确。
推荐阅读
- swift - 成功登录后 SwiftUI Firebase 身份验证关闭视图
- javascript - 如何在铯中使用折线创建轨道线?
- python - Tkinter:多项选择测验应用程序,无法更改问题(和其他问题)
- visual-studio - SSAS 表格 - 无需来自 Visual Studio 的角色即可部署
- apache-nifi - 如何使用 Jolt 到 json 数组到嵌套 json?
- flutter - Flutter 中不正确使用 ParentDataWidget
- windows - 使用 VLC 媒体播放器 CLI 音频播放时检测播放完成
- ldap - 我只需要使用 apache2 对 Splunk 进行身份验证
- virtual-reality - 在 VR 应用中防止屏幕投射、屏幕录制
- android - 无法解析 com.mapbox.navigator:mapbox-navigation-native:7.0.0