你好,我想合并两个数据帧,我在Excel加载。我将应该合并的列转换为“str”。令人惊奇的是,代码合并了第一行,但随后返回NaN值。。。。 我使用的代码是:
ListA=pd.read_excel(inpath,sheetname="Tabelle2")
ListA["Stücklistenkomponente"]=ListA["Material"].astype(np.str)
ListB=pd.read_excel(inpath,sheetname="Tabelle1")
ListB["Stücklistenkomponente"]=ListB["Material"].astype(np.str)
print(ListA.dtypes)
print(ListB.dtypes)
Material object
Material object
两个数据帧的形状为:
列表a
Material
R 22B 2.0 7.72 11.0 Lo
X 127 1.5x4.64x4[G16.05.01] CL
L 431 2x6,96x5.5 Y
9999
L 431 2x5,96x5.5 p
F 631 2x6,96x5.5 a
N 431 2x6,96x5.5 v
J 431 2x6,96x5.5
O 431 2x6,96x5.5
VM 431 2x6,96x5.5 L
列表b
Material InnerDiameter OuterDiameter Length
R 22B 2.0 7.72 11.0 Lo 2 6 8
X 127 1.5x4.64x4[G16.05.01] CL 2 7 12
L 431 2x6,96x5.5 Y 5 8 13
9999 0 0 0
L 431 2x5,96x5.5 p 6 9 15
F 631 2x6,96x5.5 a 8 5 26
N 431 2x6,96x5.5 v 9 1 3
J 431 2x6,96x5.5 12 6 89
O 431 2x6,96x5.5 5 4 12
VM 431 2x6,96x5.5 L 4 12 7
返回:
Material InnerDiameter OuterDiameter Lenth
R 22B 2.0 7.72 11.0 Lo 2 6 8
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
那我做错什么了?我认为解决方案是将两个列都转换为dtype string,但这不起作用。。。。你知道吗
谢谢你的帮助!你知道吗
我认为必须有一些不同的数据,可能是在不同的空间里,因为
.astype(str)
正确地将数据转换成string
如果in数据是
string
s、dict
s、set
s、list
s,那么dtype
就是object
。你知道吗但是
type
是string
,dict
。。。你知道吗您可以通过以下方式进行检查:
有关检查数据,请帮助生成
lists
:编辑:
我测试了你的数据,结果非常有趣:
相关问题 更多 >
编程相关推荐