Python 蟒蛇熊猫合并赢得';行不通
我有两个Python数据帧:Python 蟒蛇熊猫合并赢得';行不通,python,pandas,dataframe,merge,Python,Pandas,Dataframe,Merge,我有两个Python数据帧: 库存信息(20行): 数据(47行): Inventory\u Info.HardwareAddress的所有20个值都出现在Data.HardwareAddress中 我已经试过了,但是它没有合并数据。我从这两个数据帧中获得列名,但只包括Data的内容 finalDataSet = pandas.DataFrame.merge(Data, Inventory_Info, how='left', on='HardwareAddress') 类似地,我尝试翻转数据帧
库存信息
(20行):
数据
(47行):
Inventory\u Info.HardwareAddress
的所有20个值都出现在Data.HardwareAddress
中
我已经试过了,但是它没有合并数据。我从这两个数据帧中获得列名,但只包括Data
的内容
finalDataSet = pandas.DataFrame.merge(Data, Inventory_Info, how='left', on='HardwareAddress')
类似地,我尝试翻转数据帧顺序:
finalDataSet = pandas.DataFrame.merge(Inventory_Info, Data, how='left', on='HardwareAddress')
我得到了合并的列名,但现在只显示Inventory\u Info
数据
我已尝试使用此合并语法:
finalDataSet = webData.merge(rawData, left_index='HardwareAddress', right_on='HardwareAddress')
虽然此语法将数据转换为正确的格式并填充所有列,但数据在
硬件设计
索引上不匹配,其排列方式错误。我最终解决了此问题
Inventory\u Info.d类型
和Data.d类型
都显示硬件设计
是类型对象
。我使用了Data['HardwareAddress'].astype(int)
和Inventory\u Info['HardwareAddress'].astype(int)
,然后数据帧完全按照预期合并。我最终解决了这个问题
Inventory\u Info.d类型
和Data.d类型
都显示硬件设计
是类型对象
。我使用了Data['HardwareAddress'].astype(int)
和Inventory\u Info['HardwareAddress'].astype(int)
,然后数据帧完全按照预期合并。首先,需要发布每个数据帧的头部。接下来,将熊猫别名为pd
。最后,不要使用pandas.DataFrame.merge。使用pd.merge
。我刚才尝试了pd.merge,得到了与pd.DataFrame.merge相同的结果。请编辑您的问题并粘贴print(Data.head())
和print(Inventory\u Info.head())的结果
Inventory\u Info.HardwareAddress的所有20个值都出现在数据中。HardwareAddress…没有数据,我们无法复制,只能相信您的话。我还从两个数据帧中获取列名,但只包含数据的内容……你是说NaNs返回?请注意,您使用的是left
join,因此非匹配项会返回nan。首先,您需要发布每个数据帧的头部。接下来,将熊猫别名为pd
。最后,不要使用pandas.DataFrame.merge。使用pd.merge
。我刚才尝试了pd.merge,得到了与pd.DataFrame.merge相同的结果。请编辑您的问题并粘贴print(Data.head())
和print(Inventory\u Info.head())的结果
Inventory\u Info.HardwareAddress的所有20个值都出现在数据中。HardwareAddress…没有数据,我们无法复制,只能相信您的话。我还从两个数据帧中获取列名,但只包含数据的内容……你是说NaNs返回?请注意,您使用的是left
join,因此非匹配项不会返回NAN。
finalDataSet = pandas.DataFrame.merge(Inventory_Info, Data, how='left', on='HardwareAddress')
finalDataSet = webData.merge(rawData, left_index='HardwareAddress', right_on='HardwareAddress')