我有两个存储numpy数组的数据帧。我想将数据帧1中的所有numpy数组与数据帧2中的那些数组连接起来。我该如何存档?
一个可能的解决方案如下:
def concat_df(df, other_df):
for column in df.columns.values:
for (_, row1), (_, row2) in zip(df.iterrows(), other_df.iterrows()):
row1[column] = np.concatenate(row1[column], row2[column])
IIUC:
尝试:
out=pd.Series(np.concatenate([df['column name'].values, other_df['column name'].values]))
或
out=df['column name'].append(other_df['column name'],ignore_index=True)
或
out=pd.Series(np.hstack([df['column name'].values,other_df['column name'].values]))
现在,如果您打印out
,您将获得所需的系列
如果它们有相同的列,则可以使用pd.concat.
new_df = pd.concat([df, other_df])