python - Python - 以所需格式转置数据
问题描述
Python新手在这里。请问我怎样才能将下面给定的数据转换成下面提到的所需格式?
源数据:
输出数据必须如下所示:
请指教。
到目前为止我的代码:
# Transposing an excel file using python
import pandas as pd
# Location of the file
loc = ("C:\\Users\\user1\\Documents\\Python_Files\\data.xlsx")
# Reading the file
df=pd.read_excel("C:\\Users\\user1\\Documents\\Python_Files\\data.xlsx")
# Transposing the file
df.T.to_excel('C:\\Users\\user1\\Documents\\Python_Files\\data1.xlsx', index=False)
解决方案
pandas
您可以尝试使用带有函数pandas.read_csv
read_csv 文档的库将原始数据作为数据帧导入,然后使用函数pandas.DataFrame.transpose
transpose 文档转置数据帧
推荐阅读
- php - 仅当用户在 Laravel 5.7 中处于活动状态时才登录
- javascript - Telegram bot api 无法在 24 小时内限制用户
- performance - 在输出发生时间的同时有效地使用 iris 来组合 iris.analysis&aggregated
- ruby - 根据与 Filterrific 的关联更新过滤器
- javascript - 添加正斜杠时HTML主题jQuery中断
- oracle - Oracle PL/SQL 级联触发器删除未按预期工作
- ios - 如何从 iOS 的 Health Kit 中实时获取附近的心率数据?
- parallel-processing - 如何在 Windows 中使用 CUDA 的协作组功能
- php - 为什么我的 IntlDateFormatter 格式错误?
- r - TOML 表的 blogdown 缩进 - 特别是默认的 config.toml 文件