- 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 program in Python to create a panel from a dictionary of dataframe and print the maximum value of the first column
The result for a maximum value of the first column in panel is
maximum value of first column is ; Column1 1.377292
Solution
To solve this, we will follow the below approach −
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 the maximum value of first column using, minor_xs(0) ,
p.minor_xs(0).max()
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("maximum value of first column is:") print(p.minor_xs(0).max())
Output
Panel values: 0 1 2 0 0.914209 -0.665899 -0.703097 1 -1.375634 -0.164529 -0.673326 2 1.377292 0.692793 0.390777 3 -0.899618 -1.163681 0.954463 4 0.025898 0.832265 0.173535 maximum value of first column is: Column1 1.377292 dtype: float64
Advertisements