# ---
# 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
# ---

# # Functions of Numpy 6

import pandas as pd
from pandas import DataFrame as df
import matplotlib.pyplot as plt
import numpy as np

df_1=df(data=np.arange(12).reshape(3,4),
        index=['r0','r1','r2'],
        dtype='int',
        columns=['c0','c1','c2','c3'])

print(df_1)

print(df_1.T)

print(df_1.axes)

print(df_1.dtypes)

print(df_1.size)

print(type(df_1))

print(df_1.values)

print(type(df_1.values))

df_2=df({
    'class_1':['a','a','b','b','c'],
    'var_1':np.arange(5),
    'var_2':np.random.randn(5)}, 
    index=['r0','r1','r2','r3','r4'])

print(df_2)

print(df_2.index)

print(df_2.iloc[2:])

print(df_2.iloc[2])

print(df_2.head(3))

print(df_2.tail(3))

print(df_2.columns)

print(df_2['class_1'])

print(df_2[['class_1','var_2']])

# ==========================================================

idx=['r0','r1','r2','r3','r4']
df_1=df({'c1':np.arange(5),
         'c2': np.random.randn(5)},
        index=idx)
print(df_1)

new_idx=['r0','r1','r2','r5','r6']
df_1=df_1.reindex(new_idx)
print(df_1)

df_1=df_1.reindex(new_idx,fill_value='missing')
print(df_1)

# =========================================================

print(pd.date_range("2018-9-10", "2018-9-30", freq='B'))

date_idx=pd.date_range("09/10/2018", periods=10, freq='D')
print(date_idx)

df_2=df({"c1":[10,20,30,40,50,10,20,30,40,50]},index=date_idx)
print(df_2)

date_idx2=pd.date_range("09/05/2018", periods=20, freq='D')
print(date_idx2)

df_2=df_2.reindex(date_idx2)
print(df_2)

df_2=df_2.reindex(date_idx2, method='bfill')
print(df_2)



StarcoderdataJupyterScriptsDedupFiltered