1
在熊貓,我有一個數據幀,其中每一行對應於一個用戶,並且每個列於與該用戶,包括他們如何額定某一件事的變量:樞軸在大熊貓一系列等級列
+----------------+--------------------------+----------+----------+
| name | email | rating_a | rating_b |
+----------------+--------------------------+----------+----------+
| Someone | [email protected] | 7.8 | 9.9 |
| Someone Else | [email protected] | 2.4 | 9.2 |
| Another Person | [email protected] | 3.5 | 7.5 |
+----------------+--------------------------+----------+----------+
欲樞轉表,使得一列是評級的(a
,或b
)的類型,另一種是額定的值(7.8
,3.5
等),和其他列是與上述相同,這樣:
+----------------+-------------------------+-------------+--------------+
| name | email | rating_type | rating_value |
+----------------+-------------------------+-------------+--------------+
| Someone | [email protected] | a | 7.8 |
| Someone | [email protected] | b | 9.9 |
| Someone Else | [email protected] | a | 2.4 |
| Someone Else | [email protected] | b | 9.2 |
| Another Person | [email protected] | a | 3.5 |
| Another Person | [email protected] | b | 7.5 |
+----------------+-------------------------+-------------+--------------+
似乎熊貓melt方法是正確的,但我不完全確定我的id_vars
是什麼和我的value_vars
是在這種情況下。此外,它似乎刪除不在這兩個類別之一中的所有列,例如電子郵件地址。但我想保留所有這些信息。
我該如何與熊貓一起做這件事?