如何将熊猫数据框更改为JSON以在dygraphs中绘制数据?

时间:2017-05-18 00:07:46

标签: json pandas dataframe dygraphs

所以我需要将我的熊猫数据框更改为JSON以在dygraph中绘图。数据如下所示:

Private Sub Field1_AfterUpdate()
'Outline:
'Macro is on Form_Entry.  After user uploads an attachment into the DB via form,
'I would like to open a copy of the attachment 
'and perform additional actions on the document

'Declarations
    Dim Active_DB As DAO.Database
    Dim Active_Q As DAO.QueryDef
    Dim Active_RS, iRS As DAO.Recordset
    Dim Active_Field As DAO.Field

'Refresh form such new entry is created
    Forms!Entry.Refresh

'Connect DB
    Set Active_DB = CurrentDb
    Set Active_RS = Forms!Entry.Recordset

'Retrieve recordset of the current record entry.
    Active_RS.FindFirst "ID =" & Forms!Entry.ID.Value

'This is where I run into problems.  I am not sure what the command is to open a document.
    Set Active_Field = Active_RS!Field1.Open

    Debug.Print Active_Field.FileName

End Sub

1 个答案:

答案 0 :(得分:0)

你如何构建json?我的猜测是你可能希望每一行都作为记录,无论是否有索引号。尝试:

df.to_json(orient='records')

df.to_json(orient='index')

如果要将列标题作为键,将列数据作为json输出中的值,则可以使用:

df.to_json(orient='columns')