Skip to content

QST: With to_dict method, whether support batch transfer pd.NA in dataframe to None in dict value #51495

@flyly0755

Description

@flyly0755

Research

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/questions/43254699/pandas-to-dict-returns-none-mixed-with-nan

Question about pandas

pddata as below:
intc strc floatc
0 1 a 1
1 <NA> b 2
2 3 c 3

listdata = pddata.to_dict('records')

then listdata with value pd.NA, which is not convenient to check in the code,
[{'intc': 1, 'strc': 'a', 'floatc': 1}, {'intc': , 'strc': 'b', 'floatc': 2}, {'intc': 3, 'strc': 'c', 'floatc': 3}]
usually need loop to change all the pd.NA to None.
Whether pddata.to_dict support this data transfer and
with better performence compare to python list loop method when process large of data,
for example, a list of 10million dict element.
If not support, maybe in the futher enhence to_dict method to support it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InfoClarification about behavior needed to assess issueNeeds TriageIssue that has not been reviewed by a pandas team memberUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions