简体   繁体   English

来自Excel文件和Python的数据

[英]Data from Excel File and Python

I have this huge master excel file, and I am unpacking a few variables, and my code is expectedly not working that well. 我有一个巨大的excel主文件,并且正在解压缩一些变量,并且我的代码可能无法正常工作。 I am using Spyder for Python, and it says that there is an ordered dictionary for a few variables, and as I go to unpack the variables to plot the data its not working. 我正在使用Spyder for Python,它说有一些变量的有序字典,当我去拆包变量以绘制数据时,它不起作用。 Thanks in advance for your help. 在此先感谢您的帮助。 The Lactose are the sheet names and I am getting the data in those columns and plotting them a simple operation I thought...but it wasn't. 乳糖是工作表名称,我在那些列中获取数据并将其绘制为一个我认为很简单的操作……但事实并非如此。 My issue is that I am trying to use for loops to collect data from a master excel file, then use another for loop to grab that data and plot it. 我的问题是,我尝试使用for循环从主excel文件中收集数据,然后使用另一个for循环来获取该数据并进行绘制。 The task is to the following it should run like this read Sheet1, Sheet2, Sheet3, and so on columns A,B, M,N (not exact columns or sheetnames and then plot that data and produce pairs of graphs. The problem that is actually occurring is that it won't assign title or produce a total of 16 graphs paired into 8 sections. 任务是执行以下任务,使其像这样读取Sheet1,Sheet2,Sheet3等A,B,M,N列(不是确切的列或Sheetname,然后绘制该数据并生成成对的图形)。实际发生的情况是,它不会分配标题,也不会产生将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.)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM