熊猫将十六进制转换为负整数

时间:2018-07-18 12:18:47

标签: pandas hex

因此,我有一个熊猫数据框,其中包含一列Hex,我想将其转换为int

foo
0xff49f1
0xff49f0

以下python代码将以预期的结果完成每一行:

bar_row_1 = 0xff49f1 - int((0xff49f1 << 1) & 0x1000000)
bar_row_1 = -46607

bar_row_2 = 0xff49f0 - int((0xff49f0 << 1) & 0x1000000)
bar_row_2 = -46608

但是我想对数据框中的所有行执行此操作,并将结果输出到这样的新列中:

foo      bar
0xff49f1 -46607
0xff49f0 -46608

我的尝试如下:

df['bar'] = df['foo'].apply(lambda x: (x - int((x << 1) & 0x1000000)))

但是我得到这个错误:

TypeError: unsupported operand type(s) for <<: 'str' and 'int'

感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

您可以将基数为{ "error": { "message": "Unsupported get request. Object with ID '137340177139954' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", "type": "GraphMethodException", "code": 100, "error_subcode": 33, "fbtrace_id": "FqJ5oAqdukA" } } 的值转换为int

16