Home > Back-end >  c# DataTable to dict multiple column (ex. python dataframe.to_dict("record"))
c# DataTable to dict multiple column (ex. python dataframe.to_dict("record"))

Time:03-23

I'm using c# DataTable.

DataTable has the following format.

col1 col2 col3 col4 ...
a    b    c    d    ...
aa   bb   cc   dd   ...
...  ...  ...  ...

And the dictionary format I want is as follows.

{"col1":a, "col2":b, "col3":c, "col4":d, ...}, {"col1":aa, "col2":bb, "col3":cc, "col4":dd, ...}, ...

How can I convert like above?

In the case of python, conversion is easily possible using the dataframe.to_dict('record') function.

Thanks in advance for your reply.

CodePudding user response:

You could use a simpler, less complex method like the following post suggests. https://stackoverflow.com/a/55856220/14459189

  • Related