pandas将行头变为行值
时间: 2023-10-15 18:25:20 浏览: 90
要将行头变为行值,可以使用pandas库中的set_index()函数。该函数可以将指定的列作为行索引。首先,导入pandas库,并读取Excel文件:
import pandas as pd
a = pd.read_excel('test.xlsx', sheet_name=0)
然后,可以使用set_index()函数将“订单编号”列作为行索引:
a.set_index('订单编号')
这样就可以将行头变为行值。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python数据分析-pandas-修改行标签和列标签](https://blog.csdn.net/weixin_42403632/article/details/119820068)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [pandas将DataFrame的列变成行索引的方法](https://download.csdn.net/download/weixin_38542223/12869620)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文