草庐IT

async_read

全部标签

python - pd.read_hdf 抛出 'cannot set WRITABLE flag to True of this array'

运行时pd.read_hdf('myfile.h5')我收到以下回溯错误:[[...somelongertraceback]]~/.local/lib/python3.6/site-packages/pandas/io/pytables.pyinread_array(self,key,start,stop)24872488ifisinstance(node,tables.VLArray):->2489ret=node[0][start:stop]2490else:2491dtype=getattr(attrs,'value_type',None)~/.local/lib/python3

python - 使用 pd.read_clipboard 复制 MultiIndex 数据帧?

给定一个dataframelikethis:CAB1.111120222313.322224333655.5333226.677774如何使用pd.read_clipboard读取它?我试过这个:df=pd.read_clipboard(index_col=[0,1])但是它抛出一个错误:ParserError:Errortokenizingdata.Cerror:Expected2fieldsinline3,saw3我该如何解决这个问题? 最佳答案 更新:现在它解析剪贴板-即无需事先保存defread_clipboard_mi(i

python - 我如何在 python 多处理池 apply_async 中使用关键字参数

我正在尝试掌握python的多处理模块,特别是Pool的apply_async方法。我正在尝试调用带有参数和关键字参数的函数。如果我在没有kwargs的情况下调用该函数,那很好,但是当我尝试添加关键字参数时,我得到:TypeError:apply_async()得到了一个意外的关键字参数'arg2'下面是我正在运行的测试代码#!/usr/bin/envpythonimportmultiprocessingfromtimeimportsleepdeftest(arg1,arg2=1,arg3=2):sleep(5)if__name__=='__main__':pool=multiproc

python - Pandas - 是否可以在没有 quotechar 的情况下读取 read_csv?

我正在尝试读取一个csv文件,该文件在某些​​行中具有单个"实例,例如:car,"plane,jetjet,ski,"hat当我使用pandasread_csv读取此文件时,它会将"识别为引号字符,并且无法正确读取上面的行。我想当我使用read_csv时根本没有任何引号字符。我尝试设置quotechar=None和quotechar=''但两者都吐出一个错误,因为quotechar必须是一个长度的字符串1.是否可以在使用read_csv时根本没有quotechar?谢谢! 最佳答案 来自PandasDocumentationquot

python - pandas.read_csv 中的 dtype 和转换器有什么区别?

pandas函数read_csv()读取.csv文件。它的文档是here根据文档,我们知道:dtype:Typenameordictofcolumn->type,defaultNoneDatatypefordataorcolumns.E.g.{‘a’:np.float64,‘b’:np.int32}(Unsupportedwithengine=’python’)和converters:dict,defaultNoneDictoffunctionsforconvertingvaluesincertaincolumns.Keyscaneitherbeintegersorcolumnlabe

python - 防止 Pandas 自动推断 read_csv 中的类型

我有一个包含三列的#分隔文件:第一列是整数,第二列看起来像float,但实际上不是,第三列是字符串。我尝试使用pandas.read_csv将其直接加载到python中In[149]:d=pandas.read_csv('resources/names/fos_names.csv',sep='#',header=None,names=['int_field','floatlike_field','str_field'])In[150]:dOut[150]:Int64Index:1673entries,0to1672Datacolumns:int_field1673non-nullval

python - Matplotlib - Tcl_AsyncDelete : async handler deleted by the wrong thread?

我问这个问题是因为我无法解决Python/Django中的一个问题(实际上在纯Python中没问题)导致RuntimeError:tcl_asyncdeleteasynchandlerdeletedbythe线程错误。这在某种程度上与我在Django中呈现matplotlib图的方式有关。我的做法是:...importmatplotlib.pyplotasplt...fig=plt.figure()...plt.close()我极力简化了我的代码。但问题是——即使我只有一行代码:fig=plt.figure()我看到这个RuntimeError发生了。我希望我能解决这个问题,如果我知道

python read_fwf 错误 : 'dtype is not supported with python-fwf parser'

使用python2.7.5和pandas0.12.0,我正在尝试使用“pd.io.parsers.read_fwf()”将固定宽度字体的文本文件导入DataFrame。我导入的值都是数字,但保留前导零很重要,因此我想将dtype指定为字符串而不是int。根据documentationforthisfunction,read_fwf支持dtype属性,但是当我尝试使用它时:data=pd.io.parsers.read_fwf(文件,colspecs=([79,81],[87,90]),header=None,dtype={0:np.str,1:np.str})我得到错误:ValueEr

python - read_csv 没有正确读取此文件上的列名?

我有一个csv文件如下:05110215320425我想将其保存为名称为x,y轴的数据框,然后绘制它。但是,当我分配x,y时,我得到了一个困惑的DataFrame,发生了什么?column_names=['x','y']x=pd.read_csv('csv-file.csv',header=None,names=column_names)print(x)xy005NaN1110NaN2215NaN3320NaN4425NaN我试过没有为header指定None,但没有成功。 最佳答案 将参数sep="\s+"或delim_white

python - Django 帖子中的 "read more"

我正在django/webfaction上创建一个博客。目前我的主页显示所有帖子的所有内容。我想调整它以仅显示每篇文章的几行,并且每篇文章都以“阅读更多”链接结尾。如何做到这一点?我是django和python的新手。请帮助我。home.html中的代码:{%blockcontent%}{%forpostinobject_list%}{{post.title}}on{{post.created}}{{post.body|safe|linebreaks}}{%endfor%}{%endblock%}提前致谢。 最佳答案 您可以使用内置