【发布时间】:2017-07-09 05:56:38
【问题描述】:
我有一个 pandas.Series 和多个 str 十六进制值,例如:
74 ,68 ,69 ,73 ,20 ,69 ,73 ,20 ,6d ,79 ,20 ,74 ,65 ,78 ,74 ,20 ,74 ,6f ,20 ,68 ,65 ,78
00, ff, aa, dd, 11, 22, 33, 44, 55, 00, ff, aa, dd, 11, 22, 33, 44, 55
74 ,68 ,69 ,73 ,20 ,69 ,73 ,20 ,6d ,79 ,20 ,74 ,65 ,78 ,74 ,20 ,74 ,6f ,20 ,68 ,65 ,78
74 ,68 ,69 ,73 ,20 ,69 ,73 ,20 ,6d ,79 ,20 ,74 ,65 ,78 ,74 ,20 ,74 ,6f ,20 ,68 ,65 ,78
00, ff, aa, dd, 11, 22, 33, 44, 55, 00, ff, aa, dd, 11, 22, 33, 44, 55
我正在尝试将十六进制转换为 ascii,例如:
df['value'] = df['value'].apply(lambda x: codec.decode(x, 'hex')
我收到如下错误:
binascii.Error: decoding with 'hex' codec failed (Error: Odd-length string)
我预计某些行会出现这些错误,但需要更改可以转换为已转换状态的值。如果出现错误,我怎么能对系列的价值不做任何事情?
预期输出:
this is my text to hex
00, ff, aa, dd, 11, 22, 33, 44, 55, 00, ff, aa, dd, 11, 22, 33, 44, 55
this is my text to hex
this is my text to hex
00, ff, aa, dd, 11, 22, 33, 44, 55, 00, ff, aa, dd, 11, 22, 33, 44, 55
【问题讨论】:
标签: python python-3.x pandas hex