首页 > 解决方案 > Python - 加载具有多个标题的数据框

问题描述

我有一个数据集,其中包含不同整流器的电压和电流输出。这些值通常每两个月测量一次,因此它们具有对应的日期。目前我所做的是为每个整流器制作了一个单独的数据框,并制作了一个数据框字典。之后,我被困在如何绘制日期与电压/安培的关系上。有没有更简单的方法可以做到这一点,我可能会错过?以下是数据示例以及我的代码。

             1/1/2015           2/1/2015     3/1/2015   
Rectifier   Volts   Amps      Volts Amps    Volts   Amps
9E220ECP5001    11.10   31.95           11.30   31.05
9E220ECP5002    19.30   62.60           13.10   39.60
9E220ECP5003    4.50    6.30            4.60    6.30
9E220ECP5004    4.40    8.40            4.60    8.55
9E220ECP5005    20.90   41.40           17.60   32.07
9E220ECP5006    35.10   7.84            31.90   6.40
9E220ECP5007    13.50   22.72           17.30   29.12
9E220ECP5008    4.50    6.15            5.00    6.15


https://imgur.com/a/RJgtMWf

   
import pandas as pd

df = pd.read_excel("Rectifier_DB.xlsx", header = [0,1], index_col=0)


rectifiers = list(df.index.values)


rect_dict = {}
for index, rect in enumerate(rectifiers):
  rect_dict[rect] = pd.DataFrame(df.iloc[index])
  

标签: pythonpandas

解决方案


您可能需要定义索引列:

df = pd.read_excel('Rectifier_DB.xlsx', header=[0, 1], index_col=0)

推荐阅读