我得到了如下所示的df:
data={"name":["T1","T2","tom","adi"],
"number":["12","345","345","35"]}
df=pd.DataFrame.from_dict(data)
print(df)
并且我有for循环,在部分“名称” [“ T1”,“ tom”,“ adi”]上运行 我得到了每次迭代的新DataFrame,看起来像这样
data2={"name":["T1"],
"new":["12"],"year":["1299"],"color":["blue"]}
df2=pd.DataFrame.from_dict(data2)
print(df2)
当我尝试在循环df= pd.concat([df, df2], axis=1)
中执行concat时
我得到列[“ new”,“ year”,“ color”]
与迭代次数一样多
我希望每一列都出现一次且不超过一次。就像这里
data2={"name":["T1","T2","tom","adi"],
"new":["12","nan","45","13"],
"year":["1299","nan","1982","2000"],
"color":["blue","nan","red","yellow"]}
df=pd.DataFrame.from_dict(data2)
print(df)