JSON格式的日期

时间:2019-10-09 13:33:52

标签: json pandas date dataframe

我想将(pandas)DataFrame写入json文件。但是我的一列是日期,当我从json文件读取时,日期格式为Milliseconds(?)

const arrayOfCases = ['name', 'email', 'city', 'state', 'address']

if(arrayOfCases.includes(userInput)) {
   // your switch case here
} else {
   // handle invalid data
}

给我以下结果:

    from pandas import DataFrame, read_json
    from datetime import date

    A = {'a': [date(2019,1,1),date(2019,1,2),date(2019,1,2)], 'b': [4,5,6]}
    df = DataFrame(A)
    print(df)

    filename = r'C:\temp\Export_DataFrame.json'
    #to json file
    Export = df.to_json(filename)

    #import from json
    df2 = read_json(filename)
    print(df2)

在读取json文件时,如何转换为日期时间?

提前谢谢

1 个答案:

答案 0 :(得分:2)

read_json中使用// Header file //template < // class obj_type, // template<class> class allocator = SmartPointerAllocator, // template<class, class> class data_container = std::list> class EXPORT_OBJECT GenericConfigurationHandler { protected: typedef typename allocator<obj_type>::ClientData ClientData; typedef data_container<ClientData, std::allocator<ClientData>> TargetConfigurations; private: mutable TargetConfigurations m_target_configurations; protected: TargetConfigurations& get_target_configurations() const { return m_target_configurations; } public: /** * \brief constructor */ GenericConfigurationHandler() = default; ... }; 参数指定列名,此处为convert_dates,因为默认情况下不会解析类似日期的列:

  

转换日期:布尔值或str列表,默认为True

     

要解析日期的列列表。如果为True,则尝试解析类似日期的列。列标签与日期类似,如果

     

以'_at'结尾,
  它以“ _time”结尾,
  它以“时间戳记”开头,
  它被“修改”,或者
  现在是“日期”。

a