Convert Pandas DataFrame to JSON format

前端 未结 7 1745
野性不改
野性不改 2020-11-30 01:45

I have a Pandas DataFrame with two columns – one with the filename and one with the hour in which it was generated:

 File       Hour
  F1               


        
7条回答
  •  不知归路
    2020-11-30 02:18

    To transform a dataFrame in a real json (not a string) I use:

        from io import StringIO
        import json
        import DataFrame
    
        buff=StringIO()
        #df is your DataFrame
        df.to_json(path_or_buf=buff,orient='records')
        dfJson=json.loads(buff)
    

提交回复
热议问题