Bringing data from excel to python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Bringing data from excel to python

Hi this exemple Probabilities matrix (transition matrix) transitionMatrix = [[0.2,0.6,0.2],[0.1,0.6,0.3],[0.2,0.7,0.1]] I don't want to define the matrix i want the python brings data from excel cause i need to work with different matrix can you help please

18th Mar 2021, 3:11 PM
RIAHI CHAIMAA
RIAHI CHAIMAA - avatar
2 Answers
+ 3
if you want to bring data in from excel, you have a few options with openpyxl, pandas, and other python modules. i mainly use pandas and you can convert the pandas dataframe to a numpy array to create your matrixes. an example would be: import numpy as np import pandas as pd # type path to file here with excel extension file = “c:\\path\\file.xlsx” # by default this only reads the first sheet. you can use sheet_name option to read a specific sheet name or index or all. df = pd.read_excel(file) matrix = df.to_numpy()
18th Mar 2021, 3:42 PM
you are smart. you are brave.
you are smart. you are brave. - avatar
0
Thabk you soooo much i'll proceed as you said
18th Mar 2021, 3:55 PM
RIAHI CHAIMAA
RIAHI CHAIMAA - avatar