The following code works, however I am interested to learn if there is a more efficient way of writing to a dataframe, as opposed to 1 row at a time.
I have a json reponse workoutSamples
which contains some nested json at the "data" node which I am adding to a dataframe. So for example, is there an easier way just pull all of the d['cadence']
below into the column 'cadence' as 1 insert for the entire column in a data frame rather than looping through each node and inserting 1 row at a time?
workouts_stats_intra = pd.DataFrame(
columns=['workoutId', 'seconds', 'cadence', 'distance', 'heart_rate', 'power', 'speed'])
for d in workoutSamples:
workoutId = d["workoutId"]
logger.info("Workout Details: " + str(workoutId))
for row in d["data"]:
workouts_stats_intra.loc[len(workouts_stats_intra)] = [workoutId, row["seconds_since_pedaling_start"],
row["cadence"], row["distance"], row["heart_rate"],
row["power"], row["speed"]]