Skip to content
Advertisement

How to access matrix table value in python

How can we access the value of a matrix in Python, if I pass its column and row name as input in Python code.

For Example – If I input A as column and B as row, then from the matrix table, I should get its A and B map value.

So far I tried this code, but I was unable to figure out how to get its value:

JavaScript

Also, is it possible to achieve this solution in python 2.7?

Advertisement

Answer

Taking advantage of your created dataframe, just select according to the inputs:

JavaScript

But you can avoid the dataframe creation by creating a translation from letters to indexes using ord (assuming the inputs will always be capitalized letters, starting from A):

JavaScript

And now index the array directly:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement