
- 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 print the power of all the elements in a given series
Input − Assume, you have a series,
0 1 1 2 2 3 3 4
Output − And, the result for the power of all elements in a series is,
0 1 1 4 2 27 3 256
Solution 1
Define a Series.
Create transform method inside apply lambda power value. It is defined below, data.transform(lambda x:x**x)
data.transform(lambda x:x**x)
Solution 2
Define a Series.
Create an empty list
. Create for loop, iter all the items. Append elements to the list. It is defined below,
for i,j in data.items(): ls.append(m.pow(j,j))
Finally, convert the list into Series.
Example
Let us see the following implementation to get a better understanding.
import pandas as pd l = [1,2,3,4] data = pd.Series(l) print(data.transform(lambda x:x**x))
Output
0 1 1 4 2 27 3 256
Solution 3
Example
import pandas as pd import math as m l = [1,2,3,4] data = pd.Series(l) ls = [] for i,j in data.items(): ls.append(m.pow(j,j)) result = pd.Series(ls) print(result)
Output
0 1.0 1 4.0 2 27.0 3 256.0
- Related Questions & Answers
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to round 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 print the day of the year in a given date series
- Write a program in Python to print the elements in a series between a specific range
- Write a Golang program to print the Fibonacci series
- 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 print the length of elements in all column in a dataframe using applymap
- Python program to print all distinct elements of a given integer array.
- Write a program in Python to print the most frequently repeated element in a 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 first and last three days from a given time series data
- Python Program to print all permutations of a given string
- Write a program in Python to find the index for NaN value in a given series
Advertisements