Skip to content
Advertisement

to_json without header and index pandas

I have the following pandas DF

JavaScript

How can I convert this DF to json to be like:

JavaScript

My best try was:

JavaScript

But I got this output:

JavaScript

Bonus Doubt: Is it possible to parse only the values 1,2,3 and 4 of column data to int?

Advertisement

Answer

The first approach is to squeeze your dataframe before use to_json

JavaScript

For the bonus, use a different strategy

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