简体   繁体   中英

ERROR 'Series' object cannot be interpreted as an integer, I don't know what I do

My code:

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'])

The data is:

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

I need to convert 'LAC' in hexa.

The error arises as the function hex() operates on integers, whereas you are applying it to a pandas Series object.

Compare the behaviour of math.sin(df['LAC']) which throws an error similar to yours as math.sin() operates on single numbers (in this case floating point numbers), and np.sin(df['LAC']) , which operates on a numpy array (or similar object like a pandas Series).

One way to achieve what you want is to apply hex() to each element of the Series using a list comprehension:

h = [hex(x) for x in df['LAC']]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM