https://github.com/stitchfix/hamilton logo
#hamilton-help
Title
# hamilton-help
j

James Marvin

06/30/2022, 11:11 AM
Actually I'll rephrase the question - I am trying to do something like you can see in the picture - does anyone know how I can do that?
s

Stefan Krawczyk

06/30/2022, 2:50 PM
Homework question? are you confused about the code, or how Hamilton fits into the picture?
j

James Marvin

06/30/2022, 3:13 PM
Not homework! Just trying to understand the best way to approach the issue assuming I was using Hamilton. I ended up using something like this:
Copy code
def _nest_series(**series:pd.Series) -> pd.Series:
    df = pd.DataFrame(series)
    return df.apply(pd.Series.to_dict, axis=1)
Reason I needed to do this is because saving 'nested' data structures from Pandas into GCP is supported by the google cloud libraries
s

Stefan Krawczyk

06/30/2022, 3:26 PM
Oh yep. You're missing returning
df
in the
_nest_series
function. But yeah that's one way to do it. I was asking in relation to Hamilton because you'd need to name the function arguments rather than them being in **kwargs.
e

Elijah Ben Izzy

06/30/2022, 4:34 PM
(homework would be OK btw 🙂 )
s

Stefan Krawczyk

06/30/2022, 6:29 PM
@James Marvin e.g. :
Copy code
def my_dataframe(col_a: pd.Series, col_b: pd.Series) -> pd.DataFrame:
    return pd.DataFrame({'col_a': col_a, 'col_b': col_b})
👍 1
2 Views