python-3.x - 在 python 中使用 panda 中的 max 函数
问题描述
我正在使用 python 和 panda 在 Juypternotebook 上做一个在线教程,当我运行以下代码时,我遇到了这个错误。
抱歉,这是我第一次在堆栈溢出上发帖,所以请原谅我违反规则...
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
# reading the csv file
titanic = pd.read_csv("titanic.csv")
titanic_class = titanic.groupby("Pclass")
titanic_class.get_group(1)
titanic_class.max()
AssertionError Traceback (most recent call last)
<ipython-input-26-4d1be28a55cb> in <module>
1 #max ticket fare paid
----> 2 titanic_class.max()
~\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py in f(self, **kwargs)
1369 # try a cython aggregation if we can
1370 try:
-> 1371 return self._cython_agg_general(alias, alt=npfunc, **kwargs)
1372 except DataError:
1373 pass
~\anaconda3\lib\site-packages\pandas\core\groupby\generic.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
992 ) -> DataFrame:
993 agg_blocks, agg_items = self._cython_agg_blocks(
--> 994 how, alt=alt, numeric_only=numeric_only, min_count=min_count
995 )
996 return self._wrap_agged_blocks(agg_blocks, items=agg_items)
~\anaconda3\lib\site-packages\pandas\core\groupby\generic.py in _cython_agg_blocks(self, how, alt, numeric_only, min_count)
1098 # Clean up the mess left over from split blocks.
1099 for locs, result in zip(split_items, split_frames):
-> 1100 assert len(locs) == result.shape[1]
1101 for i, loc in enumerate(locs):
1102 new_items.append(np.array([loc], dtype=locs.dtype))
AssertionError:
有人可以告诉我有什么问题吗?titanic_class.sum() 和 titanic_class.mean() 工作没有任何错误。
解决方案
excel文件的最后一列有字母。一旦我删除它们, max 函数就起作用了。
推荐阅读
- python - 适合 Numpy 数组大小的方法?
- rust - 如何在 Rust 中存储不变类型变量
- python - 无效提交的 Django 表单数据临时在模板的其他地方使用
- vim - 在vim中搜索包含特殊字符的字符串
- vba - 访问错误“表达式可能不会导致宏名称、用户定义函数的名称或 [事件过程]”
- python - 如果预测值小于标签但如果大于标签则不增加损失
- javascript - 渲染部分视图时jQuery未定义错误
- python - keras RNN 在更少的样本上运行
- apache-spark - Spark如何查看RDD每个部分中的数据
- python-3.x - 在python中查找三个相交矩形之间的缺失坐标