Take value of a cell and store it in a variable for given values of column and row in python

Viewed 367

I want to trace back value of X and store it as a variable for given values of columns and rows.

in this case, table is relation between yield strength and slenderness ratio, provided in local building byelaws, I want to use it in a script (Rest API) and call it through flask (local host) in flutter app.

I am storing table as libre-calc/csv file, should I use sql-lite? I have tried using pandas

example, i want python to take value of sigma(pink) if value of yield strength is 250 and value of slenderness ratio is 60: table values

Stuck for couple of weeks, help will be so appreciated, thanks!

2 Answers

If you want a pandas solution, DataFrame.at() should work. You'd do df.at[60, 250], but this will only work if those values exist as row/column labels.

Assuming both values you need are on the same row it's easy to operate with them, if you want to use pandas you can simply add a new column with the desire value you need.

Example:

import pandas as pd

data = {'Name':['Jack', 'Maria', 'Alan', 'Casey'],
        'Salary':[2400, 3000, 2000, 1700],
        'Rent_Cost':[900, 850, 550, 650]
       }

df = pd.DataFrame(data)

df['Salary_%_Spent'] = round((df['Rent_Cost']/df['Salary']*100), 2)

This would result in:

enter image description here

Now if you prefer this as a variable...

percentageSpent = round((df['Rent_Cost']/df['Salary']*100), 2)

If you already have the column with the values you need then it becomes way easier.

percentageSpent = df['Salary_%_Spent']

or

caseyPercentage = df['Salary_%_Spent'][df['Name']=='Casey']

I hope this helps you, or at least guide you to solve your issue.

Related