相关疑难解决方法(0)

熊猫长期以来通过两个变量进行广泛重塑

我有长格式的数据,我试图重塑到宽,但似乎没有一个直接的方法来使用融化/堆栈/取消堆栈:

Salesman  Height   product      price
  Knut      6        bat          5
  Knut      6        ball         1
  Knut      6        wand         3
  Steve     5        pen          2
Run Code Online (Sandbox Code Playgroud)

变为:

Salesman  Height    product_1  price_1  product_2 price_2 product_3 price_3  
  Knut      6        bat          5       ball      1        wand      3
  Steve     5        pen          2        NA       NA        NA       NA
Run Code Online (Sandbox Code Playgroud)

我认为Stata可以使用reshape命令执行类似的操作.

python reshape pandas

30
推荐指数
6
解决办法
5万
查看次数

标签 统计

pandas ×1

python ×1

reshape ×1