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

"""

A) Series

"""

# pass list, tuple, or array & pandas makes the indeces automatically
future_array1 = [1,2,3,4,5,6] # 1 dimensional array
array1 = np.array(future_array1)
s = pd.Series(array1)
s

"""

B) DataFrame

"""

# DataFrame: object that can contain more than 1 Series
dates = pd.date_range("20180101", periods=10)
data = np.random.random((10,3))
df = pd.DataFrame(data, index=dates, columns=['Column1', 'Column2', 'Column3'])
df

# DataFrames, unlike Arrays, can store elements of different data types!
df['Column4'] = pd.Series([True, False, False, False, True, True, False, True, True, False], index=dates)

df

"""

C) Upload Data

"""

uploaded_data = pd.read_csv("filename.csv", index_col=0)

"""

D) View Data

"""

# View the top of the data set
df.head(3) # <- can leave it (), defaults to 5

# View the bottom of the data set
df.tail(3) # <- can leave it (), defaults to 5

# View each piece of the DataFrame
print (df.index)
print ("")
print (df.columns)
print ("")
print (df.values)

# View description statistics
print (df.describe())

"""

E) Indexing

"""

# Column names
df['Column2']

# Row Indeces
df[0:2] # or df['20180101':'20180102']

# Multi-axis with label
df.loc['20180101':'20180102',['Column1','Column3']]

# Multi-axis with indexing
df.iloc[3:5, 0:2]

df.iloc[4:8, 3:4]

# Boolean
df[df.Column1 > .5]

"""

F) Iterating

"""

for index, row in df.iterrows():
    print (index, row[0])

"""

G) Reshaping & Sorting

"""

# Transpose
df.T

# Sort by Index
df.sort_index(axis=0, ascending=False)

# Sort by Values
df.sort_values(by='Column2')

"""

H) Join & Group

"""

# Join
data1 = np.random.random((10,2))
data2 = np.random.random((10,2))
df1 = pd.DataFrame(data1, index=dates, columns=['ColumnA', 'ColumnB'])
df2 = pd.DataFrame(data2, index=dates, columns=['ColumnC', 'ColumnD'])
df1.join(df2) # joins on the index, you can join on other columns with: pd.merge(df1, df2, on="column_name", how='left')

# Group
df.groupby('Column4').corr()



StarcoderdataJupyterScriptsDedupFiltered