Python 连接数据帧中的行

Python 连接数据帧中的行,python,pandas,dataframe,Python,Pandas,Dataframe,这看起来应该简单得多,但我在这里 我试图从另一个数据帧向一个数据帧(确切地说是两个数据帧)添加一行,但出现以下错误: TypeError: cannot concatenate object of type "<class 'numpy.float64'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid 我是否必须将数据['AB\''的第一次出现]、数据['AB\''的相似性]转换为另

这看起来应该简单得多,但我在这里

我试图从另一个数据帧向一个数据帧(确切地说是两个数据帧)添加一行,但出现以下错误:

TypeError: cannot concatenate object of type "<class 'numpy.float64'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
我是否必须将
数据['AB\''的第一次出现]、数据['AB\''的相似性]
转换为另一个数据帧?这似乎效率极低

编辑:我尝试了
y=pd.concat([y,pd.Series(data['Class'])])
,但它将数据作为一个新列追加,例如
y


您需要首先转换为数据帧:

X = pd.concat([X,pd.DataFrame([[data['first occurrence of \'AB\''],data['similarity to \'AB\'']]],columns=['first occurrence of \'AB\'','similarity to \'AB\''])], ignore_index=True)
y = pd.concat([y,pd.DataFrame([data['Class']], columns=['Class'])], ignore_index=True)

编辑:add ignore_index=True

首先尝试将向量转换为pd.Series:example:y=pd.concat([y,pd.Series(data['Class]])))@CoMartel,但这似乎将该系列添加为一个新列(将用屏幕截图更新我的问题)添加示例输入和预期输出My bad:我认为您需要首先将数据转换为数据帧。请看Ok,所以我尝试了这个,但我得到了这个错误:ValueError:传递值的形状是(1,2),索引暗示(2,2)在哪一行?在X行(或者如果我注释掉X,我在y行得到“ValueError:DataFrame构造函数未正确调用!”)
数据是什么样子的?我添加了一些缺少的[],你能再试一次吗?
X = pd.concat([X,pd.DataFrame([[data['first occurrence of \'AB\''],data['similarity to \'AB\'']]],columns=['first occurrence of \'AB\'','similarity to \'AB\''])], ignore_index=True)
y = pd.concat([y,pd.DataFrame([data['Class']], columns=['Class'])], ignore_index=True)