简体   繁体   English

如何连接两个 pandas 列并使用该行创建一个新列?

[英]How can I concat Two pandas columns and create a new with the row?

Hello I have the following pandas您好我有以下 pandas

A B C
l 1 4
c 2 5
d 3 6

How can I conver that on我怎样才能将其转换为

A E T
l 1 B
c 2 B
d 3 B
l 4 C
c 5 C
d 6 C

Thanks谢谢

I just want to add a little to @Quang Hoang's answer to complete the solution.我只想在@Quang Hoang 的回答中添加一些内容以完成解决方案。

df = df.melt('A')
df.rename(columns={'variable': 'T', 'value': 'E'}, inplace = True)

暂无
暂无

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

相关问题 关于concat在pandas中的使用:使用行数据创建新列 - about concat in pandas : using row data to create new columns 如何从下一行开始让Pandas在新的列中创建总和? - How can I get Pandas to create sumsum in new columns by starting at the next row down? 如何“行绑定”具有不同列的两个熊猫数据框? - How can I 'row bind' two pandas dataframes with different columns? 如何在 Pandas 中使用 groupby 创建新列? - How can I create new columns with groupby in pandas? 将函数应用于pandas数据帧的每一行以创建两个新列 - Apply function to each row of pandas dataframe to create two new columns Concat与Pandas的两列 - Concat two columns with Pandas Pandas Dataframe:如何比较一行的两列中的值是否等于后续行的同一列中的值? - Pandas Dataframe: how can i compare values in two columns of a row are equal to the ones in the same columns of a subsequent row? 如何迭代 Pandas 中的列值并根据同一行中多列的值创建新的观察? - How can I iterate over column values in Pandas and create a new observation based on the values of multiple columns in the same row? 如果每列每行有多个值,如何在熊猫数据框中的两列之间创建字典? - How can I create a dictionary between two columns within a pandas dataframe if each column has more than one value per row? 如何创建一个包含两列组合的新列? - how can I create a new column with two columns combination?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM