
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Write a Python program to find the average of first row in a Panel
Assume, you have Panel and the average of the first row is,
Average of first row is: Column1 0.274124 dtype: float64
Solution
To solve this, we will follow the steps given below −
Set data value as dictionary key is ‘Column1’ with value as pd.DataFrame(np.random.randn(5, 3))
data = {'Column1' : pd.DataFrame(np.random.randn(5, 3))}
Assign data to Panel and save it as p
p = pd.Panel(data)
Print the column using dict key Column1
print(p['Column1'])
Calculate theAverage of first row using, major_xs(0) ,
p.major_xs(0).mean()
Example
Let’s see the following code to get a better understanding −
import pandas as pd import numpy as np data = {'Column1' : pd.DataFrame(np.random.randn(5, 3))} p = pd.Panel(data) print("Panel values:") print(p['Column1']) print("Average of first row is:") print(p.major_xs(0).mean())
Output
Panel values: 0 1 2 0 0.629910 0.275741 -0.083281 1 -0.509143 -1.794204 0.300390 2 -1.944141 0.085508 -0.155167 3 1.551087 -0.671242 -0.838922 4 -0.643543 0.622777 1.112745 Average of first row is: Column1 0.274124 dtype: float64
- Related Articles
- Write a program in Python to create a panel from a dictionary of dataframe and print the maximum value of the first column
- Get the Average of Average in a single MySQL row?
- Write a Python program to find the maximum value from first four rows in a given series
- Write a program in Python to perform average of rolling window size 3 calculation in a given dataframe
- Write a program in Python to remove first duplicate rows in a given dataframe
- How to find the first empty row of an excel file in Python?
- MySQL query to calculate the average of values in a row?
- Python program to find the redundancy rates for each row of a matrix
- Find average of a list in python?
- Write a program in Python to find the lowest value in a given DataFrame and store the lowest value in a new row and column
- Program to find average waiting time in Python
- Program to find smallest intersecting element of each row in a matrix in Python
- PHP program to find the average of the first n natural numbers that are even
- Write a program in Python to find the maximum length of a string in a given Series
- Write a program in Python to find the minimum rank of a particular column in a dataframe

Advertisements