Skip to content
Advertisement

convert dataframe row to dict

I have datarame like the sample data below. I’m trying to convert one row from the dataframe in to a dict like the desired output below. But when I use to_dict I get the indice along with the column value. Does anyone know how to get convert the row to a dict like the desired output? Any tips greatly appreciated.

JavaScript

Advertisement

Answer

Try adding .to_dict('records')[0] to the row you want

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement