【发布时间】:2016-11-07 20:47:44
【问题描述】:
我在名为 RateMatrix1 的 Excel 文件中的不同工作表中存储了不同的模型和初始值。我的模型是 WIN、WSW、WPA、WFR……我的初始值是 WI、WS、WP、WF……,Excel 上的工作表就是这样命名的。
现在,我想编写一个函数,它使用模型名称和初始值作为下面的“工作表名称”。我想知道是否有办法在 python 中这样做。
import pandas as pd
import numpy as np
def MLA(model, initialValues)
RMatrix=(pd.read_excel("C:\Anaconda3\RateMatrix1.xlsx", sheetname="model", skiprows=0)).as_matrix() #read the matrix values from excel spreadsheet, and converts the values to a matrix
initialAmount = (pd.read_excel("C:\Anaconda3\RateMatrix1.xlsx", sheetname="initialValues", skiprows=0)).as_matrix() #read the column matrix (initial values) from excel spreadsheet, and converts the values to a matrix
return np.dot(RMatrix,initialAmount)
print(MLA(WIN,WI))
【问题讨论】:
标签: python excel pandas function