Write a Python code to create a series with your range values, generate a new row as sum of all the values and then convert the series into json file

PythonPandasServer Side ProgrammingProgramming

Solution

To solve this, we will follow the steps given below −

  • Define a series with a range of 1 to 10

  • Find the sum of all the values

  • Convert the series into JSON file format

Let us see the following implementation to get a better understanding.

Example

import pandas as pd
data = pd.Series(range(1,11))
data['sum'] = data.sum()
data = data.to_json()
print(data)

Output

{"0":1,"1":2,"2":3,"3":4,"4":5,"5":6,"6":7,"7":8,"8":9,"9":10,"sum":55}
raja
Published on 10-Feb-2021 13:19:59
Advertisements