Selecting the minimum value of column from a SQL table, translated to Python's pandas.
Selecting a single column's minimum value
In SQL:
SELECT
MIN(column_1)
FROM
table;
In pandas:
table['column_1'].min()
Selecting the minimum of multiple columns
In SQL:
SELECT
MIN(column_1),
MIN(column_2)
FROM
table;
In pandas:
table
.agg({'column_1': ['min'], 'column_2': ['min']})
Selecting the minimum of columns with an alias
In SQL:
SELECT
column_1,
MIN(column_2) AS min_alias_1,
MIN(column_3) AS min_alias_2
FROM
table
GROUP BY
column_1;
In pandas:
table
.groupby('column_1')
.agg(min_alias_1=('column_2', 'min'), min_alias_2=('column_3', 'min'))