ColumnMedian
Gets the median value of one or more columns. Furthermore, can get the median while being grouped by another column or category, perform a rolling median or sliding window median, can get the median for only rows that meet a condition, and can add the result to the dataframe as a new column
Options
columns: Specifies columns to calculate median values
where: Specifies a condition for the calculation
group: Groups the data before performing the operation
rolling: Specifies the rolling window overwhich to perform the calculation
addToDataframe: Indicates whether to add the result to the dataframe
Examples
Example 1 - Get Median of a Single Column
The median is a useful measure of central tendency that is less affected by outliers than the mean. In this example, we compute the median of the Pressure3pm column and print the result directly to the console.
#> ColumnMedian Pressure3pm --print
AFLEFT
weatherDfMedian = weatherDf['Pressure3pm'].median()
print(weatherDfMedian) #)2 AFRIGHT
Example 2 - Get Median of Multiple Columns
When summarizing a dataset across several columns, calculating the median for each helps highlight central values while minimizing the influence of outliers. Here, we compute the median for Evaporation, Rainfall, and Cloud9am all at once.
#> ColumnMedian Evaporation Rainfall Cloud9am --print
AFLEFT
weatherDfMedian = weatherDf [ [Evaporation, Rainfall, 'Cloud9am'] ].median()
print(weatherDfMedian) #)4 AFRIGHT