我正在尝试将df编写为xml文件。我的问题是如何在xml输出中执行分组依据。
我的输入数据作为csv文件:
user_id|acnt_id|transaction|desc
1 |1234| 012345| desc1
1 |1234| 102345| desc2
1 |5678| 123454| desc1
2 |1234| 345672| desc1
我正在读取csv文件并将其写为xml文件,我想知道在编写xml时如何指定嵌套模式。
目前我能得到的
<transactions>
<transaction>
<user_id>1</user_id>
<acnt_id>1234</acnt_id>
<transaction>012345</transaction>
<desc>desc1</desc>
</transaction>
<transaction>
<user_id>1</user_id>
<acnt_id>1234</acnt_id>
<transaction>102345</transaction>
<desc>desc2</desc>
</transaction>
<transaction>
<user_id>1</user_id>
<acnt_id>5678</acnt_id>
<transaction>123454</transaction>
<desc>desc1</desc>
</transaction>
<transaction>
<user_id>2</user_id>
<acnt_id>1234</acnt_id>
<transaction>345672</transaction>
<desc>desc2</desc>
</transaction>
</transactions>
预期o / p
<transactions>
<transaction>
<user_id>1</user_id>
<acnt_id>1234</acnt_id>
<transaction>012345</transaction>
<desc>desc1</desc>
<transaction>102345</transaction>
<desc>desc2</desc>
<acnt_id>5678</acnt_id>
<transaction>123454</transaction>
<desc>desc1</desc>
</transaction>
<transaction>
<user_id>2</user_id>
<acnt_id>1234</acnt_id>
<transaction>345672</transaction>
<desc>desc2</desc>
</transaction>
</transactions>