Reputation: 1
I am new to python. I need to store some data from excel file in some way (instead of accessing the excel every time). My data looks like this:
Parameter | Minvalue | Maxvalue |
---|---|---|
param1 | 5 | 10 |
param2 | 19 | 30 |
param3 | -1 | 10 |
I need to store it and access it by referring to the parameter name.
What is the best way to do that, I have some hundreds of parameters.
Apart from accessing, I may need to update them too.
Upvotes: 0
Views: 496
Reputation: 21
You might want to use pandas https://pandas.pydata.org/.
This library can also read excel files:
https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html
For instance in you case:
import pandas as pd
df = pd.read_excel('myfile.xlsx')
Set the index on column Parameter:
df.set_index('Parameter', inplace=True)
Now access a cell like this:
df.loc['param1', 'Minvalue']
# 5
And write to the cell:
df.loc['param1', 'Minvalue'] = 6
# Read value again:
df.loc['param1', 'Minvalue']
# 6
Upvotes: 1