I'm trying switch my code from pandas to polars.
there's a list of dict as below:
data = [{
"MA5": 91.128,
"MA10": 95.559,
"MA20": 103.107,
"MA30": 109.3803,
"MA60": 114.0822
},
{
"MA5": 13.776,
"MA10": 14.027,
"MA20": 13.768,
"MA30": 13.6417,
"MA60": 14.0262
}]
I want to create a series from this list in polars, and then add it to a existed dataframe.
I try many ways, but all those lost the key name, only value field left, like below:
Series: 'ma' [struct[5]]
[
{14.426,13.718,12.672,12.7723,14.1927}
{14.59,13.898,12.735,12.7497,14.1378}
{14.352,13.951,12.7785,12.721,14.0727}
{14.134,13.967,12.857,12.7493,14.0027}
{13.966,14.062,12.979,12.7987,13.9532}
]
but I need to keep the dict type in series, hope the series as below:
Series: 'ma' [struct[5]]
[
{
"MA5": 91.128,
"MA10": 95.559,
"MA20": 103.107,
"MA30": 109.3803,
"MA60": 114.0822
},
{
"MA5": 13.776,
"MA10": 14.027,
"MA20": 13.768,
"MA30": 13.6417,
"MA60": 14.0262
}
]
What is the right way to achieve this goal in polars or in pyarrow?