How to get the powers of an array values element-wise in Python-Pandas? Last Updated : 18 Aug, 2020 Comments Improve Suggest changes Like Article Like Report Let's see how to get the powers of an array values element-wise. Dataframe/Series.pow() is used to calculate the power of elements either with itself or with other Series provided. This function is applicable for real numbers only, and doesn't give results for complex numbers. So let's see the programs: Example 1: The uni-dimensional arrays are mapped to a pandas series with either default numeric indices or custom indexes Then corresponding elements are raised to its own power. Python3 # import required modules import numpy as np import pandas as pd # create an array sample_array = np.array([1, 2, 3]) # uni dimensional arrays can be # mapped to pandas series sr = pd.Series(sample_array) print ("Original Array :") print (sr) # calculating element-wise power power_array = sr.pow(sr) print ("Element-wise power array") print (power_array) Output: Example 2: Powers can also be computed for floating-point decimal numbers. Python3 # module to work with arrays in python import array # module required to compute power import pandas as pd # creating a 1-dimensional floating # point array containing three elements sample_array = array.array('d', [1.1, 2.0, 3.5]) # uni dimensional arrays can # be mapped to pandas series sr = pd.Series(sample_array) print ("Original Array :") print (sr) # computing power of each # element with itself power_array = sr.pow(sr) print ("Element-wise power array") print (power_array) Output: Example 3: The Multi-dimensional arrays can be mapped to pandas data frames. The data frame then contains each cell comprising a numeric (integer or floating-point numbers) which can be raised to its own individual powers. Python3 # module to work with # arrays in python import array # module required to # compute power import pandas as pd # 2-d matrix containing # 2 rows and 3 columns df = pd.DataFrame({'X': [1,2], 'Y': [3,4], 'Z': [5,6]}); print ("Original Array :") print(df) # power function to calculate # power of data frame elements # with itself power_array = df.pow(df) print ("Element-wise power array") print (power_array) Output: Comment More infoAdvertise with us Next Article How to get the powers of an array values element-wise in Python-Pandas? Y yashchuahan Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Python Pandas-exercise Practice Tags : python Similar Reads NumPy | Get the Powers of Array Values Element-Wise To calculate the power of elements in an array we use the numpy.power() method of NumPy library. It raises the values of the first array to the powers in the second array. Example:Python3 import numpy as np # creating the array sample_array1 = np.arange(5) sample_array2 = np.arange(0, 10, 2) print(" 3 min read How to access the last element in a Pandas series? Prerequisite: Pandas Pandas series is useful in handling various analytical operations independently or as being a part of pandas data frame. So it is important for us to know how various operations are performed in pandas series. The following article discusses various ways in which last element o 3 min read How to Make Arrays fit into Table in Python Pandas? To convert arrays into a table (DataFrame) in Python using the Pandas library, you can follow the steps depending on the structure of your array:1. One-Dimensional ArrayTo convert a one-dimensional NumPy array into a DataFrame, use the pd.DataFrame() method and specify column names for better readab 2 min read Access the elements of a Series in Pandas Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). Labels need not be unique but must be a hashable type. Let's discuss different ways to access the elements of given Pandas Series. First create a Pandas Series. Python 2 min read Multiply Each Value In A Column By A Row in Python Pandas In Python Data Analysis and Manipulation, it's often necessary to perform element-wise operations between rows and columns of DataFrames. This article focuses on multiplying values in a column by those in a row, a task achievable using Pandas, NumPy, or even basic Python list comprehension. Understa 3 min read Get the substring of the column in Pandas-Python Now, we'll see how we can get the substring for all the values of a column in a Pandas dataframe. This extraction can be very useful when working with data. For example, we have the first name and last name of different people in a column and we need to extract the first 3 letters of their name to c 2 min read How to Select Column Values to Display in Pandas Groupby Pandas is a powerful Python library used extensively in data analysis and manipulation. One of its most versatile and widely used functions is groupby, which allows users to group data based on specific criteria and perform various operations on these groups. This article will delve into the details 5 min read How to extract the value names and counts from value_counts() in Pandas ? Prerequisites: panda matplotlib In this article, we will learn how we can extract the names and values using values_count() from panda. The panda library is equipped with a number of useful functions for 'value_counts' is one of them. This function returns the counts of unique items in a pandas dat 3 min read Log and natural Logarithmic value of a column in Pandas - Python This article explores the computation of logarithmic and natural logarithmic values for a column in Pandas using Python. What is Log and Natural Logarithmic?A logarithm is a mathematical function that represents the exponent to which a base must be raised to produce a given number. The logarithm of 4 min read Python | Pandas DataFrame.values Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 2 min read Like