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