example: in this link, price and units columns need to transformed in to separate rows
请参阅图片说明链接。
Name item variable Price variable Units
0 Vehicle Car Wk1 price 978 Wk1 units 100
1 Vehicle Car Wk2 price 966 Wk2 units 120
当我使用熔化时,我将价格和单位都放在一列中。 有没有办法将价格和单位作为单独的列
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
有没有办法以下面的格式获得输出?
mvn -U clean install
答案 0 :(得分:0)
我试了一下
第1步 - 创建数据框
data = pd.DataFrame([{"Name":"Vehicle", "item":"Car", "Wk1 price":978, "Wk2 price":966, "Wk1 units":100, "Wk2 units":120}])
步骤2 - 融合数据框并分离“度量”和“值”
data = data.melt(id_vars = ['Name', 'item'])
data["Week"] = [re.findall("[AaZz]*.*?(?=\s)",x)[0] for x in data["variable"]]
data["Metric"] = [re.findall("\s([AaZz]*.*)",x)[0] for x in data["variable"]]
data = data.drop(["variable"],axis=1)
第3步 - 透过数据框
data.pivot_table(index=["Name","item","Week"], columns="Metric", values="value").reset_index()