You can also compute the values in the Data Frame using df.sum(), df.mean(), df.median(), df.mode()
and more.
pandas.DataFrame.median — pandas 2.3.2 documentation
Import the library:
import pandas as pd
The following dataset is given
data = {
"WorkerID": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"Age": [25, 35, 35, 30, 24, 28, 28, 32, 27, 28],
"Salary": [50000, 54000, 40000, 58000, 45000, 60000, 49000, 52000, 50000, 47000]
}
Create the data frame:
df = pd.DataFrame(data)
print(df)
Output:
WorkerID Age Salary
0 1 25 50000
1 2 35 54000
2 3 35 40000
3 4 30 58000
4 5 24 45000
5 6 28 60000
6 7 28 49000
7 8 32 52000
8 9 27 50000
9 10 28 47000
df = pd.DataFrame(data)
# Shape of the dataset
row, column = df.shape
print("Rows:", row)
print("Columns:", column)
Output:
Rows: 10
Columns: 3