# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as np

df = pd.DataFrame({'col1': [2, 3, 1, 3, 3, 4],
                   'col2': [30, 10, 10, 40, 40, 20]},
                  index=['A', 'B', 'C', 'D', 'E', 'F'])
print(df)

s = df['col1']
print(s)

print(df.max())

print(type(df.max()))

print(df.min())

print(type(df.min()))

print(df.max(axis=1))

print(df.min(axis=1))

print(s.max())

print(type(s.max()))

print(s.min())

print(type(s.min()))

print(s.nlargest(4))

print(type(s.nlargest(4)))

print(s.nsmallest(4))

print(type(s.nsmallest(4)))

print(s.nlargest(1))

print(type(s.nlargest(1)))

print(df.nlargest(4, 'col1'))

print(type(df.nlargest(4, 'col1')))

print(df.nsmallest(4, 'col1'))

print(type(df.nsmallest(4, 'col1')))

print(df.nlargest(1, 'col1'))

print(type(df.nlargest(1, 'col1')))

print(df.nlargest(4, ['col1', 'col2']))

print(df.nlargest(4, ['col2', 'col1']))

print(df.nsmallest(4, 'col1'))

print(df.nsmallest(4, 'col1', keep='first'))

print(df.nsmallest(4, 'col1', keep='last'))

print(df.nsmallest(4, 'col1', keep='all'))

print(df.nsmallest(3, ['col1', 'col2'], keep='all'))

print(df.nsmallest(4, ['col1', 'col2'], keep='all'))

print(df['col1'].nsmallest(4).tolist())

print(type(df['col1'].nsmallest(4).tolist()))

print(df['col1'].nsmallest(4).to_numpy())

print(type(df['col1'].nsmallest(4).to_numpy()))

print(df['col1'].nsmallest(4).values)

print(type(df['col1'].nsmallest(4).values))

print(df['col1'].nsmallest(3))

print(df['col2'].nsmallest(3))

print([df[col_name].nsmallest(3).tolist() for col_name in df])

print({col_name: col.nsmallest(3).tolist() for col_name, col in df.iteritems()})

print(np.array([df[col_name].nsmallest(3).tolist() for col_name in df]))

print([df[col_name].nsmallest(3, keep='all').tolist() for col_name in df])

print({col_name: col.nsmallest(3, keep='all').tolist() for col_name, col in df.iteritems()})

print(np.array([df[col_name].nsmallest(3, keep='all').tolist() for col_name in df]))

StarcoderdataJupyterScriptsDedupFiltered