草庐IT

converts

全部标签

python xlrd : how to convert an extracted value?

好吧,我有一个问题,根据我在这里找到的内容,我觉得我已经回答了好几次。然而,作为一个新手,我真的不能理解如何执行一个真正基本的操作。事情是这样的:我有一个.xls,当我使用xlrd获取一个值时,我只是在使用sh.cell(0,0)(假设sh是我的工作表);如果单元格中的内容是字符串,我会得到类似text:u'MyName'的内容,我只想保留字符串'MyName';如果单元格中的内容是数字,我会得到类似于number:201.0的内容,我只想保留整数201。如果有人能告诉我我应该如何只提取我想要的格式的值,谢谢。 最佳答案 sh.ce

Python 类型错误 : cannot convert the series to <class 'int' > when trying to do math on dataframe

我有一个看起来像这样的数据框:defaultdict(,{'XYF':TimeUSGyrXGyrYGyrZAccX\02071465700.0008329140.001351716-0.0004189798-0.65118312071866710.0019627870.001242457-0.0001859666-0.642349722072267919.520243E-050.001076498-0.0005664826-0.636041232072464740.00010930590.0016169170.0003615251-0.634287542072862440.001412

python - Lame MP3 Converter 的 Python 等价物是什么?

我需要在服务器端将mp3音频文件转换为64kbps。现在,我正在使用subprocess来调用lame,但我想知道是否有任何好的替代方案? 最佳答案 这里似乎有一个关于该主题的旧线程:http://www.dreamincode.net/forums/topic/72083-lame-mp3-encoder-for-python/最后的结论是通过Python->C绑定(bind)创建到lame_enc.dll的自定义绑定(bind)。得出该结论的原因是现有的绑定(bind)库(pymedia/py-lame)没有得到维护。不幸的是,

python gettext 错误 : Can't convert '__proxy__' object to str implicitly

我突然在之前运行的代码中遇到了一个奇怪的错误。我最近从1.9.4升级到Django1.9.6。在我的一个观点中,我有:fromdjango.contribimportmessagesfromdjango.utils.translationimportugettext_lazyas_messages.success(request,str(_('Astringwitha')+''+_('link!')+'.'),extra_tags="safehtml")这现在在倒数第二行给出了一个TypeError:Can'tconvert'__proxy__'objecttostrimplicitl

python - PIL : Convert RGB image to a specific 8-bit palette?

使用Python图像库,我可以调用img.convert("P",palette=Image.ADAPTIVE)或img.convert("P",palette=Image.WEB)但有没有办法转换成任意调色板?p=[]foriinrange(0,256):p.append(i,0,0)img.convert("P",palette=p)它将在哪里将每个像素映射到图像中找到的最接近的颜色?还是Image.WEB仅支持此功能? 最佳答案 在查看convert()的源代码时,我发现它引用了im.quantize。quantize可以采用

python - 类型错误 : cannot convert the series to <class 'float' >

我有一个数据框(df),如下所示:dateA2001-01-021.00222001-01-031.10332001-01-041.14962001-01-051.10332015-03-30126.37002015-03-31124.43002015-04-01124.25002015-04-02124.8900对于整个时间序列,我尝试将今天的值除以昨天的值并使用以下内容记录结果:df["B"]=math.log(df["A"]/df["A"].shift(1))但是我得到以下错误:TypeError:cannotconverttheseriesto我该如何解决这个问题?我尝试使用以

python - 在 Pandas 中,为什么 tz_convert 将使用的时区从 EST 更改为 LMT?

在下面的脚本中,为什么tz和tz2不同?importpandasimportpytztz=pytz.timezone('US/Eastern')t=pandas.Timestamp('2014-03-0308:05:39.216809')tz2=t.tz_localize(pytz.UTC).tz_convert(tz).tz在这种情况下,tz显示为:但是tz2显示为:pandas不应该尊重我传递给tz_convert的时区吗?(这可能是一个已知错误吗?)更新:这似乎更像是一个关于pytz的问题。仍然让我感到困惑(但可能有明确解释)的行为是为什么跟随不同?tztz.localize(t

python /Matplotlib : convert Axis ⇔ Data coordinates systems

我的问题很简单:在matplotlib中,如何轻松地将轴系统中的坐标与数据系统进行转换(理想情况下,我正在寻找一个简单的函数output_coords=magic_func(input_coords))实际上我的确切问题是:我想绘制一个matplotlib.patches.Ellipse,其中心在Axis系统中,但其大小(宽度和长度)在Data系统中。但是transforms.blended_transform_factory方法在这种情况下不起作用。谢谢! 最佳答案 要从Axes实例ax获取转换,您可以使用axis_to_data

python - psycopg2 "TypeError: not all arguments converted during string formatting"

我正在尝试将二进制数据(漩涡哈希)插入PG表,但出现错误:TypeError:notallargumentsconvertedduringstringformatting代码:cur.execute("""INSERTINTOsessions(identity_hash,posted_on)VALUES(%s,NOW())""",identity_hash)我尝试在插入之前将conn.Binary("identity_hash")添加到变量中,但得到了同样的错误。identity_hash列是一个bytea。有什么想法吗? 最佳答案

python - Numpy->Cython 转换 : Compile error:Cannot convert 'npy_intp *' to Python object

我有以下代码可以正确转换为cython:fromnumpyimport*##returnswinningplayersor[]ifundecided.defscore(board):scores=[]checked=zeros(board.shape)foriinxrange(len(board)):forjinxrange(len(board)):ifchecked[i,j]==0andboard[i,j]!=0:...dostuf我尝试转换为cython:importnumpyasnpcimportnumpyasnp@cython.boundscheck(False)@cython