Python:Merge-TypeError:不可散列的类型:'dict'

时间:2020-01-23 15:08:19

标签: python-3.x pandas merge typeerror

我有两个数据数据帧:

 import mygeotab as geo
 import pandas as pd
 api = geo.API(username='**********', password='*********', database='*********')
 loc = api.get('DeviceStatusInfo')
 df1 = pd.DataFrame(loc)
 df2 = pd.read_csv(r"C:\Users\AFSERVICES-2\OneDrive - Above Ground Marketing\AF Projects\Dev       \GeoTab_id_list.csv")
 df1 = df1.drop(['bearing','currentStateDuration','exceptionEvents','isDeviceCommunicating','isDeviceCommuni    cating','dateTime','isHistoricLastDriver','groups'],axis=1)
 df1 = df1[['device','driver','latitude','longitude','speed','isDriving']]
 df2.rename(columns={'device':'id'}, inplace=True)
 df1.rename(columns={'device':'id'}, inplace=True)
 >>> df1
       id           driver   latitude   longitude  speed  isDriving
 0   {'id': 'b49'}    {'id': 'b1F'}  32.709248  -97.937584  105.0       True
 1   {'id': 'b60'}    {'id': 'bFF'}  32.677555  -97.072617   41.0       True
 2   {'id': 'b53'}    {'id': 'bB7'}  32.710709  -96.341431  111.0       True
 3   {'id': 'b68'}    {'id': 'b50'}  33.255295  -94.841141  109.0       True
 4   {'id': 'b5A'}   {'id': 'b149'}  34.356915  -98.409599   98.0       True
 ..           
 83  {'id': 'b6E'}  UnknownDriverId  31.716249 -106.218651    0.0      False
 84  {'id': 'b67'}  UnknownDriverId  31.716736 -106.218979    0.0      False
 85  {'id': 'b71'}   {'id': 'b155'}  31.716532 -106.219009    0.0      False
 86  {'id': 'b36'}  UnknownDriverId  31.729588 -106.237366    0.0      False
 87  {'id': 'b4E'}  UnknownDriverId  31.716556 -106.218575    0.0      False

 [88 rows x 6 columns]

 >>> df2
       id  truck
 0   {'id': 'b9'}   AF008
 1   {'id': 'b1E'}  AF009
 2   {'id': 'b7'}   AF012
 3   {'id': 'b10'}  AF013
 4   {'id': 'bF'}   AF014
 ..            
 87  {'id': 'b72'}  AF099
 88  {'id': 'b73'}  AF100
 89  {'id': 'b41'}   LS01
 90  {'id': 'b42'}   LS02
 91  {'id': 'b43'}   LS03

 [92 rows x 2 columns]

我要合并它们,匹配'id'

 df3 = pd.merge(df1,df2,on='id')

但是我得到这个错误:

TypeError:不可散列的类型:'dict'

我想将gps跟踪设备的“ id”号与卡车的实物号相匹配。我已经为此工作了两天,并尝试了不同的方法。如果我没有输入错误,我会得到索引错误

0 个答案:

没有答案