Skip to content
Advertisement

Change dates to quarters in JSON file Python

I’m trying to convert the dates inside a JSON file to their respective quarter and year. My JSON file is formatted below:

JavaScript

The current code I’m using is an attempt of using the pandas.Series.dt.quarter as seen below:

JavaScript

The issue I face is that my code isn’t comprehending the object name “lastDate”. My ideal output should have the dates ultimately replaced into their quarter, check below:

JavaScript

Advertisement

Answer

You can use this bit of code instead:

JavaScript

json object is different than pd.DataFrame. You have to convert json to pd.DataFrame first using from_dict() function.

Advertisement