你好,我有一个值的dateframe1,我想把它转换成一个新的dataframe2,通过连接原始dataframe1中列的值,即
dataframe1
ProductName Value otherValue
Product1 2 5
Product2 3 2
Product1 1 5
Product3 4 7
Product3 5 7
Product1 5 5
Product2 9 2
dataframe2
ProductName Value otherValue
Product1 2 1 5 5
Product2 3 9 2
Product3 4 5 7
你可以用两行字试试这个。首先,我们需要将列
Value
转换为字符串,以便执行连接和操作,第二个是返回所需输出的所有操作:打印(df) 输出:
您可以按
ProductName
分组,并使用Value
上的' '.join
和first
在otherValue
上进行聚合:输出
请注意,此解决方案假定列值不是字符串,否则可以直接使用
' '.join
相关问题 更多 >
编程相关推荐