python pd merge_python pandas-pd.merge上的keyError,即使数据帧中存在相同的列

我正在尝试在多个列上联接两个数据帧。即使两个数据帧中都存在所有列,我在执行pd.merge时也会得到一个键错误。

当我尝试加入时,我会

"ValueError: len(left_on) must equal the number of levels in the index of "right""

数据帧1:

>>data.columns

Index(['weather.description', 'weather.icon', 'weather.id', 'weather.main',

'dt', 'main.pressure', 'main.temp_min', 'main.temp_max', 'main.temp',

'main.humidity', 'main.grnd_level', 'main.sea_level', 'wind.speed',

'wind.deg', 'wind.gust', 'id', 'day', 'month', 'hour', 'dd', 'year'],

dtype='object')

>>data.dtypes

weather.description object

weather.icon object

weather.id int64

weather.main object

dt object

main.pressure float64

main.temp_min float64

main.temp_max float64

main.temp float64

main.humidity int32

main.grnd_level float64

main.sea_level float64

wind.speed float64

wind.deg float64

wind.gust float64

id float64

day object

month object

year object

hour object

dd object

dtype: object

数据帧2:

>>df_crime.columns

Index(['beat', 'disposition', 'event_date', 'event_number', 'general_location',

'location_1', 'map_x', 'map_y', 'type', 'type_description', 'ward',

'day', 'year', 'month', 'dd', 'hour'],

dtype='object')

>>df_crime.dtypes

beat object

disposition object

event_date object

event_number object

general_location object

location_1 object

map_x float64

map_y float64

type object

type_description object

ward float64

day object

year object

month object

dd object

hour object

dtype: object

内部联接查询:

result = pd.merge(data,

df_crime[['type_description']],

on=['year','month','dd','hour']

)

错误:

KeyError: 'year'

我这里缺什么?


版权声明:本文为weixin_42395498原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。