- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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}
Advertisements