![](/img/trans.png)
[英]I don't understand this error: TypeError: 'float' object cannot be interpreted as an integer
[英]ERROR 'Series' object cannot be interpreted as an integer, I don't know what I do
我的代码:
import pandas as pd
datos=pd.read_csv('/Users/rafaelsuarez/Documents/Data/UCELL.csv', sep=',' , encoding='latin-1')
df=pd.DataFrame(datos)
df['RNC']=df['RNC'].map('RNC_{}'.format)
h=hex(df['LAC'])
数据是:
MCC,MNC,LAC,CELLID,CELLNAME,RNC,NODEBNAME,AZIMUTH_ANTENNA,LON,LAT
730,09,119,20011,AIS_3G_001_1_B1,PTM01,AIS_3G_001,20,-72.6906,-45.4044
730,09,119,20014,AIS_3G_001_1_B2,PTM01,AIS_3G_001,20,-72.6906,-45.4044
我需要将 'LAC' 转换为六进制。
由于函数hex()
对整数进行运算,而您将其应用于 pandas Series 对象,因此会出现错误。
比较math.sin(df['LAC'])
的行为,它抛出与您类似的错误,因为math.sin()
对单个数字(在这种情况下为浮点数)和np.sin(df['LAC'])
,它在一个 numpy 数组(或类似的对象,如熊猫系列)上运行。
实现您想要的一种方法是使用列表理解将hex()
应用于系列的每个元素:
h = [hex(x) for x in df['LAC']]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.