来自 Excel 文件和 Python 的数据

Data from Excel File and Python

我有这个巨大的主 excel 文件,我正在解压缩一些变量,我的代码预计不会很好地工作。我正在为 Python 使用 Spyder,它说有一些变量的有序字典,当我去解压缩变量以绘制数据时它不起作用。在此先感谢您的帮助。乳糖是 sheet 名称,我正在获取这些列中的数据并绘制它们,我认为这是一个简单的操作......但事实并非如此。我的问题是我正在尝试使用 for 循环从主 excel 文件收集数据,然后使用另一个 for 循环获取该数据并绘制它。任务是以下它应该 运行 像这样读取 Sheet1、Sheet2、Sheet3 等 A、B、M、N 列(不是确切的列或 sheet 名称,然后绘制该数据和生成成对的图。实际发生的问题是它不会分配标题或生成总共 16 个图配对成 8 个部分。

import pandas as pd
import scipy as sp
from scipy import constants
import numpy as np
import matplotlib.pyplot as plt


d = ['Lactose.450g.2p', 'Lactose.229g.16p', 'Lactose.343g.16p', 
 'Lactose.375g.2p','Lactose.400g.16p', 'Lactose.419g.16p', 
 'Lactose.425g.2p', 'Lactose.500g.2p']
for i in d:
       reference = []
       list_reference  = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i])
       reference.append(list_reference)
       xaxis_samp = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'C' , skiprows = [0,1])
       yaxis_samp = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'D' , skiprows = [0,1])
       xaxis_ref = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'I', skiprows = [0,1])
       yaxis_ref = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols ='J', skiprows = [0,1])
       for e1, e2, e3, e4, e5 in zip(xaxis_samp,yaxis_samp,xaxis_ref,yaxis_ref, [i]):
           fig_ref, [ax1, ax2] = plt.subplots(nrows = 2, ncols = 1, figsize = (10,10))
           ax1.plot(e3, e4)
           ax1.set_title( 'Reference Spectrum Teflon Tablet')
           ax1.grid(True)
           ax1.set_xlim(0,3)
           ax1.set(xlabel = 'TeraHertz (THz)', ylabel = 'Electric field (a.u.)')
           ax2.plot(e1,e2)
           ax2.set_title('Sample Spectrum ' + str(e5) + ' Tablet')
           ax2.grid(True)
           ax2.set_xlim(0,3)
           ax2.set(xlabel = 'TeraHertz (THz)', ylabel = 'Electric field (a.u.)')
import pandas as pd
import scipy as sp
from scipy import constants
import numpy as np
import matplotlib.pyplot as plt


d = ['Lactose.450g.2p', 'Lactose.229g.16p', 'Lactose.343g.16p', 
     'Lactose.375g.2p','Lactose.400g.16p', 'Lactose.419g.16p', 
     'Lactose.425g.2p', 'Lactose.500g.2p']
for i in d:
     reference = []
     list_reference  = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i])
     reference.append(list_reference)
     xaxis_samp = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'C' , skiprows = [0,1])
     yaxis_samp = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'D' , skiprows = [0,1])
     xaxis_ref = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols = 'I', skiprows = [0,1])
     yaxis_ref = pd.read_excel('C:\Kean\MasterFileLactose071019.xlsx', sheet_name = [i], usecols ='J', skiprows = [0,1])
     for e1, e2, e3, e4, e5 in zip(xaxis_samp,yaxis_samp,xaxis_ref,yaxis_ref,d):
     fig_ref, [ax1, ax2] = plt.subplots(nrows = 2, ncols = 1, figsize = (10,10))
           ax1.plot(xaxis_ref[e3], yaxis_ref[e4])
           ax1.set_title( 'Reference Spectrum Teflon Tablet')
           ax1.grid(True)
           ax1.set_xlim(0,3)
           ax1.set(xlabel = 'TeraHertz (THz)', ylabel = 'Electric field (a.u.)')
           ax2.plot(xaxis_samp[e1],yaxis_samp[e2])
           ax2.set_title('Sample Spectrum Tablet of '+ i)
           ax2.grid(True)
           ax2.set_xlim(0,3)
           ax2.set(xlabel = 'TeraHertz (THz)', ylabel = 'Electric field (a.u.)')