Tag: 集团的

pandas与多种数据types的系列崩溃

我有一个简单的Excel文件有两列 – 一个分类列和另一个数字列,我读入pandas与read_excel函数如下 df= pd.read_excel('pandas_crasher.xlsx') 第一列是具有多种types的Objecttypes。 由于excel格式不正确,该列包含时间戳,浮点数和文本的组合。 但它通常应该只是一个简单的文本列 from datetime import datetime from collections import Counter df['random_names'].dtype DTYPE( 'O') print Counter([type(i) for i in load_instance['random_names']]) Counter({type'unicode'>:15427,type'datetime.datetime'>:18,type'float'>:2}) 当我做了一个简单的groupby,它crashes the python kernel没有任何错误消息或通知 – 我试图从jupyter和一个小的自定义烧瓶应用程序没有任何运气。 df.groupby('random_names')['random_values'].sum() <<崩溃 它是一个700kb(15k行和2列)相对较小的文件 – 所以它绝对不是一个内存问题 我试着用pdb进行debugging,以便跟踪崩溃点,但是无法越过pandas / core / groupby.py模块中的cython函数 def _cython_operation(self,kind,values,how,axis) 在pandas可能的错误 – 而不是直接崩溃不应该它抛出一个exception,并优雅地退出? 然后我使用以下函数将各种数据types转换为文本 def custom_converter(x): if isinstance(x,datetime) or isinstance( x, […]