@@ -571,11 +571,13 @@ def to_flatten_inner(self, field: str) -> pd.Series:
571
571
572
572
Examples
573
573
--------
574
+
574
575
>>> from nested_pandas import NestedFrame
575
576
>>> from nested_pandas.datasets import generate_data
576
577
>>> nf = generate_data(5, 2, seed=1).rename(columns={"nested": "inner"})
577
578
578
579
Assign a repeated ID to double-nest on
580
+
579
581
>>> nf["id"] = [0, 0, 0, 1, 1]
580
582
>>> nf
581
583
a b inner id
@@ -584,6 +586,7 @@ def to_flatten_inner(self, field: str) -> pd.Series:
584
586
2 0.000114 0.691121 [{t: 4.089045, flux: 31.342418, band: 'g'}; …]... 0
585
587
3 0.302333 0.793535 [{t: 17.562349, flux: 69.232262, band: 'r'}; …... 1
586
588
4 0.146756 1.077633 [{t: 0.547752, flux: 87.638915, band: 'g'}; …]... 1
589
+
587
590
>>> nf.inner.nest.to_flat()
588
591
t flux band
589
592
0 8.38389 80.074457 r
@@ -598,16 +601,19 @@ def to_flatten_inner(self, field: str) -> pd.Series:
598
601
4 3.96203 87.81425 r
599
602
600
603
Create a dataframe with double-nested column "outer"
604
+
601
605
>>> dnf = NestedFrame.from_flat(nf, base_columns=[], on="id", name="outer")
602
606
603
607
Flat "inner" nested column.
604
608
This is like "concatenation" of the initial nf frame on duplicated `id` rows
609
+
605
610
>>> concated_nf_series = dnf["outer"].nest.to_flatten_inner("inner")
606
611
>>> concated_nf_series
607
612
id
608
613
0 [{a: 0.417022, b: 0.184677, t: 8.38389, flux: ...
609
614
1 [{a: 0.302333, b: 0.793535, t: 17.562349, flux...
610
615
Name: outer, dtype: nested<a: [double], b: [double], t: [double], flux: [double], band: [string]>
616
+
611
617
>>> concated_nf_series.nest.to_flat() # doctest: +NORMALIZE_WHITESPACE
612
618
a b t flux band
613
619
id
0 commit comments