获得以下数据帧:
Body Weight (KG) Exercise 1 Weight (KG) Exercise 2 \
Date
17/07/17 77.9 Squat 20.0 Bench Press
Weight (KG).1 Exercise 3 Weight (KG).2
Date
17/07/17 20.0 Barbell Row 30.0
试图重塑成一种整洁的形式:
Date Body Weight Exercise Weight
17/07/17 77.9 Squat 20.0
17/07/17 77.9 Bench Press 20.0
17/07/17 77.9 Barbell Row 30.0
尝试使用熔融函数
pd.melt(df,value_vars=["Exercise 1","Exercise 2","Exercise 3"])
导致:
variable value
0 Exercise 1 Squat
1 Exercise 2 Bench Press
2 Exercise 3 Barbell Row
如何将重量和其他列与正确的日期和练习“对齐”?你知道吗
您可以首先通过^{} 将
Body Weight (KG)
列添加到MultiIndex
,然后使用重复的index
值调用DataFrame
构造函数。你知道吗Notice
-需要在所有列中使用Exercise
和Weight
对,而不使用第一对来获得正确的输出相关问题 更多 >
编程相关推荐