简体   繁体   English

如何根据行/列名称将一个数据框的列附加为另一个数据框的行?

[英]How to append column of one data frame as row of another data frame based on row/column name?

I have 2 data frames, df1:我有 2 个数据框,df1:

    x1  x2  x3  x4  x5
y1
y2
y3
y4
y5

and df2:和 df2:

    y1  y2  y3  y4  y5
z1
z2
z3
z4
z5

I want to append the values of df1 as a row in df2 by comparing the row/column names in the dataframes.我想通过比较数据帧中的行/列名称,将 df1 的值作为 df2 中的一行附加。 I did this using Numpy but I want to do this using Pandas.我使用 Numpy 做到了这一点,但我想使用 Pandas 做到这一点。 Kindly help.请帮忙。

can you just create a transponse of df2 and then append/merge/"add" to df1?你能创建一个 df2 的转发,然后附加/合并/“添加”到 df1 吗?

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.transpose.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.transpose.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在一列,一行一行地比较Pandas数据帧? - How to do Pandas data frame comparison on one column, row by row? 根据列值突出显示数据框中的行? - Highlight row in a data frame based on a column value? 如何根据该行中的条件为另一个数据框中的每一行选择一个数据框? - How can I get a selection of one data frame for each row in another data frame based on conditions in that row? 如何根据特定行的列值查询 pandas 数据帧 - How to query on a pandas data frame based on column values of specific row pandas:如何根据列值在一个数据帧中从另一个数据帧中 append 行? - pandas: How can I append rows in one data frame from another based on column values? 我需要基于列名从一个数据框到另一个数据框的值在 python pandas 中 - I need values from one data frame to another data frame in python pandas based on column name 如何从另一个数据框中获取值的行列名称 - How to get the row-column name of a value from another data frame Pandas Python-如何将数组(与数据框的长度不同)转换为数据框,并保留行名和列名? - pandas python - how to convert array (different length with data frame) to data frame and keep the row and column name? Python数据框:如果列名称包含在另一列的字符串行中,则为1,否则为0 - Python Data frame: If Column Name is contained in the String Row of Another Column Then 1 Otherwise 0 如何根据列名将一个数据框中的列值复制到另一个数据框中? - How do I copy the value of columns in one data frame to another data frame based on column names?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM