In [ ]:
import os

import pandas as pd
import numpy as np
import cellpy

Crating some dataframes and collecting them into a dictionary


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
}

Trying some solutions that might help in getting tab-completion


In [ ]:
from collections import namedtuple

In [ ]:
ExperimentsTuple = namedtuple('MyTuple', sorted(df_dict))

In [ ]:
current_experiments = ExperimentsTuple(**df_dict)

In [ ]:
current_experiments.second.current

One-liner...


In [ ]:
c_experiments = namedtuple("experiments", sorted(df_dict))(**df_dict)

In [ ]:
c_experiments.first.a

Using box


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.

What I have learned

Tab completion can probably be easiest implemented by creating namedtuple if I dont want to depend on other packages. However, using python box gives the added benefit of also allowing dictionary-type look-up in addtion to . based.

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()])

Conclussion

Lets go for python box


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 [ ]: