草庐IT

non-integer

全部标签

Python Pandas : output dataframe to csv with integers

我有一个希望导出到CSV文件的pandas.DataFrame。但是,pandas似乎将一些值写为float而不是int类型。我找不到如何改变这种行为。构建数据框:df=pandas.DataFrame(columns=['a','b','c','d'],index=['x','y','z'],dtype=int)x=pandas.Series([10,10,10],index=['a','b','d'],dtype=int)y=pandas.Series([1,5,2,3],index=['a','b','c','d'],dtype=int)z=pandas.Series([1,2,

尝试按索引访问列表时出现 Python 错误 - "List indices must be integers, not str"

我有以下Python代码:currentPlayers=query.getPlayers()forplayerincurrentPlayers:returnstr(player['name'])+""+str(player['score'])我收到以下错误:TypeError:listindicesmustbeintegers,notstr我一直在寻找与我接近的错误,但不知道该怎么做,从未遇到过该错误。所以是的,我怎样才能将它转换为整数而不是字符串?我猜问题出在str(player['score']). 最佳答案 您是否希望play

python - NumPy/OpenCV 2 : how do I crop non-rectangular region?

我有一组构成形状(闭合折线)的点。现在我想从此形状内的某个图像中复制/裁剪所有像素,其余部分为黑色/透明。我该怎么做呢?例如,我有这个:我想得到这个: 最佳答案 *edit-已更新以处理具有Alphachannel的图像。这对我有用:制作一个全黑的蒙版(全蒙版)按照ROI的形状用白色填充多边形将蒙版和您的图像结合起来,以获得黑色的ROI对于接受掩码的函数,您可能只想将图像和掩码分开。但是,我相信这可以满足您的具体要求:importcv2importnumpyasnp#originalimage#-1loadsas-issoifitw

python - 类型错误 : only integer arrays with one element can be converted to an index

使用交叉验证执行递归特征选择时出现以下错误:Traceback(mostrecentcalllast):File"/Users/.../srl/main.py",line32,inargident_sys.train_classifier()File"/Users/.../srl/identification.py",line194,intrain_classifierfeat_selector.fit(train_argcands_feats,train_argcands_target)File"/Library/Frameworks/Python.framework/Version

Python: "TypeError: __str__ returned non-string"但仍打印输出?

我有这段代码可以创建一个新的注释..当我尝试打印时,即使它打印输出,我也会收到以下错误Error:C:\Python27\Basics\OOP\formytesting>pythonnotebook.pyMemo=Thisismyfirstmemo,Tag=exampleTraceback(mostrecentcalllast):File"notebook.py",line14,inprint(firstnote)TypeError:__str__returnednon-string(typeNoneType)note.pyimportdatetimeclassNote:def__in

python 'list indices must be integers, not tuple"

这两天我一直在努力解决这个问题。我是python和编程的新手,所以此类错误的其他示例对我没有太大帮助。我正在阅读列表和元组的文档,但没有找到任何有用的东西。任何指针将不胜感激。不一定要寻找答案,只是寻找更多资源。我正在使用Python2.7.6。谢谢measure=raw_input("Howwouldyouliketomeasurethecoins?Enter1forgrams2forpounds.")coin_args=[["pennies",'2.5','50.0','.01']["nickles",'5.0','40.0','.05']["dimes",'2.268','50.

python - TypeError : string indices must be integers, not str//使用 dict

我正在尝试定义一个过程,involved(courses,person),它将类(class)结构和人员作为输入,并返回描述该人员所参与的所有类(class)的字典。这是我的involved(courses,person)函数:definvolved(courses,person):fortime1incourses:forcourseincourses[time1]:forinfointime1[course]:printinfo这是我的字典:courses={'feb2012':{'cs101':{'name':'BuildingaSearchEngine','teacher':'

Python NLTK : SyntaxError: Non-ASCII character '\xc3' in file (Sentiment Analysis -NLP)

我正在使用NLTK来完成关于情绪分析的任务。我正在使用Python2.7。NLTK3.0和NumPy1.9.1版本。这是代码:__author__='karan'importnltkimportreimportsysdefmain():print("Start");#gettingthestopwordsstopWords=open("english.txt","r");stop_word=stopWords.read().split();AllStopWrd=[]forwdinstop_word:AllStopWrd.append(wd);print("stopwords->",Al

Python Pandas 用户警告 : Sorting because non-concatenation axis is not aligned

我正在做一些代码练习并在执行此操作时应用数据帧的合并收到用户警告/usr/lib64/python2.7/site-packages/pandas/core/frame.py:6201:FutureWarning:Sortingbecausenon-concatenationaxisisnotaligned.Afutureversionofpandaswillchangetonotsortbydefault.Toacceptthefuturebehavior,pass'sort=True'.Toretainthecurrentbehaviorandsilencethewarning,p

python - 为什么我会收到 TypeError : can't multiply sequence by non-int of type 'float' ?

这个问题在这里已经有了答案:HowcanIreadinputsasnumbers?(10个回答)I'mgettingaTypeError.HowdoIfixit?(2个回答)关闭2个月前。我正在输入一个销售金额(通过输入)乘以定义的销售税(0.08),然后让它打印总金额(销售税乘以销售金额)。我遇到了这个错误。任何人都知道可能出了什么问题或有任何建议吗?salesAmount=raw_input(["Insertsaleamounthere\n"])['Insertsaleamounthere\n']20.99>>>salesTax=0.08>>>totalAmount=salesAm