请建议如何在Pandas dataframe中完成:
Current in the Pandas dataframe(df)
Id Phone Email workplace Mailing city Mailing Stat
123 12345 123@1233.de test New York New York
abc 45678 abc@ab.de test New York New York
def 78019 def@def.de test New York New York我正在看下面提到的熊猫数据格式。
id Attribute Value Mailing city Mailing sat
123 Phone 12345 New York New York
123 Email 123@1233.de New York New York
123 workplace test New York New York
abc phone 45678 New York New York
abc email abc@ab.de New York New York
abc workplace test 发布于 2022-10-18 11:36:29
我复制了这个结果,并利用熔融函数得到了下面的结果。
Pandas dataframe

所需结果的代码:
import pandas as pd
result_df= pd.melt(p_df, id_vars="Id", value_vars=["Phone","Email","workplace"],var_name="Attribute", value_name="Value")
result_df=result_df.sort_values('Id')
result_df执行:

https://stackoverflow.com/questions/74109618
复制相似问题