

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 program in Python to round all the elements in a given series
Input −
Assume, you have a Series,
0 1.3 1 2.6 2 3.9 3 4.8 4 5.6
Output −
0 1.0 1 3.0 2 4.0 3 5.0 4 6.0
Solution 1
Define a Series
Create an empty list. Set the for loop to iter the data. Append round of values to the list.
Finally, add the elements to the series.
Example
Let us see the complete implementation to get a better understanding −
import pandas as pd l = [1.3,2.6,3.9,4.8,5.6] data = pd.Series(l) print(data.round())
Output
0 1.0 1 3.0 2 4.0 3 5.0 4 6.0
Solution 2
Example
import pandas as pd l = [1.3,2.6,3.9,4.8,5.6] data = pd.Series(l) ls = [] for i,j in data.items(): ls.append(round(j)) result = pd.Series(ls) print(result)
Output
0 1 1 3 2 4 3 5 4 6
- Related Questions & Answers
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to print the power of all the elements in a given series
- Write a program in Python to sort all the elements in a given series in descending order
- Write a program in Python to filter only integer elements in a given series
- Write a program in Python to find the missing element in a given series and store the full elements in the same series
- Write a program in Python to filter valid dates in a given series
- Write a program in Python to filter armstrong numbers in a given series
- Write a program in Python to print the elements in a series between a specific range
- Write a program in Python to find the index for NaN value in a given series
- Write a program in Python to find the maximum length of a string in a given Series
- Write a program in Python to print the day of the year in a given date series
- Write a program in Python to replace all odd index position in a given series by random uppercase vowels
- Write a program in Python to slice substrings from each element in a given series
- Write a program in Python to check if a series contains duplicate elements or not
- Write a Python program to find the maximum value from first four rows in a given series
Advertisements