Code Explanation:
Import the Pandas Library
import pandas as pd
Imports the pandas library and assigns it an alias pd.
pandas is used for data manipulation and working with tables (DataFrames).
Create a DataFrame
df = pd.DataFrame({"a": [1, 2, 3]})
A DataFrame named df is created.
It has one column named "a" with values: 1, 2, 3
The DataFrame looks like:
index a
0 1
1 2
2 3
Calculate the Sum of the Column
total = df["a"].sum()
df["a"] selects the column "a".
.sum() adds all the values in that column.
So 1 + 2 + 3 = 6
The result is stored in the variable total.
Calculate the Maximum Value in the Column
mx = df["a"].max()
.max() finds the largest value in the "a" column.
The maximum number is 3
The result is stored in mx.
Print the Results
print(total, mx)
This prints both values — the sum and the max.
Final output:
6 3
Final Output
6 3
.png)

0 Comments:
Post a Comment