In [ ]:
import os
import pandas as pd
import numpy as np
import cellpy
In [ ]:
df1 = pd.DataFrame(data=np.random.rand(5,3), columns=["a b c".split()])
In [ ]:
df2 = pd.DataFrame(data=np.random.rand(5,3), columns=["current voltage capacity".split()])
In [ ]:
df3 = pd.DataFrame(data=np.random.rand(5,3), columns=["d e f".split()])
In [ ]:
df_dict = {
"first": df1,
"second": df2,
"third": df3
}
In [ ]:
from collections import namedtuple
In [ ]:
ExperimentsTuple = namedtuple('MyTuple', sorted(df_dict))
In [ ]:
current_experiments = ExperimentsTuple(**df_dict)
In [ ]:
current_experiments.second.current
In [ ]:
c_experiments = namedtuple("experiments", sorted(df_dict))(**df_dict)
In [ ]:
c_experiments.first.a
In [ ]:
import box
In [ ]:
df_box = box.Box(df_dict)
In [ ]:
df_box.first
In [ ]:
df_box["first"]
In [ ]:
df_box["new_df"] = pd.DataFrame(data=np.random.rand(5,3), columns=["one two three".split()])
In [ ]:
df_box.new_df
In [ ]:
df_box["20190101_FC_data_01"] = pd.DataFrame(data=np.random.rand(5,3), columns=["foo bar baz".split()])
However, starting keys with integers does not seem to work when using box for tab completion.
By the way, Jupyter can tab-complete dictionary keys also.
In [ ]:
df_dict["first"]
In [ ]:
df_dict["20190101_FC_data_01"] = pd.DataFrame(data=np.random.rand(5,3), columns=["foo bar baz".split()])
In [ ]:
cell_id = "20190101_FC_data_01"
pre = ""
new_id = "".join((pre, cell_id))
new_id
In [ ]:
new_id.split("cell_")
In [ ]:
new_id.lstrip("cell_")
In [ ]: