# ---
# 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 numpy as np
import pandas as pd

type(np.arange(9).reshape((3,3)))

data = pd.DataFrame(np.arange(16).reshape(4,4), index=['Ohio', 'Colorado', 'Utah', 'New York'], columns=['one', 'two', 'three', 'four'])

data

data[:2]

data.iloc[:3]

data.loc[:'Utah', 'two']

data[data.three > 5]

data.loc['Ohio', 'one']

ser = pd.Series(np.arange(3.))

ser

ser[0]

ser2 = pd.Series(np.arange(3.), index=['a', 'b', 'c'])

ser2

ser2[-1]

ser2['a']

import pandas as pd
import numpy as np

df = pd.DataFrame({'key1' : ['a', 'a', 'b', 'b', 'a'],
'key2' : ['one', 'two', 'one', 'two', 'one'],
'data1' : np.random.randn(5),
'data2' : np.random.randn(5)})

df

grouped = df['data1'].groupby(df['key1'])

grouped.mean()

grouped = df['data1'].groupby([df['key1'], df['key2']])

means = grouped.mean()

means.unstack()

states = np.array(['Ohio', 'California', 'California', 'Ohio', 'Ohio'])

years = np.array([2005, 2005, 2006, 2005, 2006])

df

df[['data1', 'data2']]

df['data1']

type(df['data1'])

df['data1'].max()

df['data1'].min()

pd.Series(10)



StarcoderdataJupyterScriptsDedupFiltered