Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EHN: A function to read dict from values_to_dict returns #589

Open
Zeroto521 opened this issue Jun 26, 2022 · 2 comments
Open

EHN: A function to read dict from values_to_dict returns #589

Zeroto521 opened this issue Jun 26, 2022 · 2 comments
Labels
idea A prototype idea

Comments

@Zeroto521
Copy link
Owner

>>> import json
>>> import dtoolkit.accessor
>>> import pandas as pd
>>> df = pd.DataFrame(
...     {
...         "x" : ["A", "A", "B", "B", "B"],
...         "y" : ["a", "b", "c", "d", "d"],
...         "z" : ["1", "2", "3", "3", "4"],
...     }
... )
>>> df
    x  y  z
0  A  a  1
1  A  b  2
2  B  c  3
3  B  d  3
4  B  d  4

Turn the above case into the following case.

>>> import json
>>> import dtoolkit.accessor
>>> import pandas as pd
>>> df = func(
...     {
...         "A": {
...             "a": ["1"],
...             "b": ["2"],
...         },
...         "B": {
...             "c": ["3"],
...             "d": ["3", "4"],
...         },
...     }
... )
>>> df
    x  y  z
0  A  a  1
1  A  b  2
2  B  c  3
3  B  d  3
4  B  d  4
@Zeroto521
Copy link
Owner Author

dict could convert to series or dataframe. But the index may lose.

@Zeroto521
Copy link
Owner Author

a easy way to convert to series.

>>> pd.Series({'a': [1, 2]}).explode()
a    1
a    2
dtype: object

@Zeroto521 Zeroto521 added the idea A prototype idea label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea A prototype idea
Projects
None yet
Development

No branches or pull requests

1 participant