2016-11-07 1 views
0

Ich habe verschiedene Modelle und initialValues ​​in verschiedenen Tabellen in einer Excel-Datei namens RateMatrix1 gespeichert. Meine Modelle sind WIN, WSW, WPA, WFR ... und meine initialValues ​​sind WI, WS, WP, WF ... und die Blätter in Excel werden genau so benannt.Verwenden Sie Spreadsheet-Namen als Variablen in Pandas

Jetzt möchte ich eine Funktion schreiben, die den Namen des Modells und die initialValues ​​als "Sheetnamen" unten verwendet. Ich habe mich gefragt, ob es in Python einen Weg dafür gibt.

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)) 

Vielen Dank für Ihre Hilfe.

Antwort

0

Nevermind ... Ich habe eine Lösung gefunden.

Für alle anderen suchen das Gleiche zu tun, hier ist mein Code:

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")) 
Verwandte Themen