<jupyter_start><jupyter_text>Pandas"pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language."* https://pandas.pydata.org/The ** pandas ** package is a package for handling data frames and time series data. Along with the array of ** numpy ** packages, we can use it to perform regression analysis or various financial analyzes.<jupyter_code># import numpy and pandas
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>SeriesVariables used in pandas consist of **series** and **dataframe**.* series: a column vector* dataframe: a set of column vectors<jupyter_code>## Series sample
series1 = pd.Series(np.random.rand(10),name = 'series1')
type(series1)
# Vector multiplied by a constant
series1 * 1000
# Summary Statistics
series1.describe()
# Assign row names 
series1.index = ['a','b','c','d','e','f','g','h','i','j']
series1
# Show index in series
series1.index
# Choose data
print(series1['g'])
print(series1[6])<jupyter_output>0.2553045273793483
0.2553045273793483<jupyter_text>dataframeA data frame can be said to be a combination of series, and has independent characteristics for each column.<jupyter_code># Create dict 
dict1 = {
    'column1' : [1,2,3,4,5],
    'column2' : ['amazon','ms','apple','google','samsung'],
    'returns' : np.random.rand(5)
}
type(dict1)
# Convert Dict to dataframe
dfram = pd.DataFrame(dict1,pd.date_range('2015-01-01',periods=5))
dfram

# data frame columns and index
dfram.index<jupyter_output><empty_output><jupyter_text>dataframe을 인덱싱하는 함수로는 iloc가 있고, 각 행좌표와 열좌표를 인자로 한다.<jupyter_code># iloc
dfram.iloc[1:3,0:3]<jupyter_output><empty_output><jupyter_text>**dataframe**을 또 다른 인덱싱하는 함수로는 loc가 있고, 각 행이름과 열이름를 인자로 한다.<jupyter_code># use to_datetime function
dfram.loc[pd.to_datetime(['2015-01-01','2015-01-03']),['column1','column2']]
# Combine Series : pd.concat function
series1 = pd.Series(np.random.rand(10),name = 'series1')
series2 = pd.Series(np.random.rand(10),name = 'series2')
series3 = pd.Series(np.random.rand(10),name = 'series3')
dfram2 = pd.concat([series1,series2,series3],axis=1)
dfram2<jupyter_output><empty_output><jupyter_text>**dataframe**을 직접 웹에서 받아오는 방법도 존재한다. 웹에서 받는 경우는 야후 파이낸스에서 데이터를 가져오는 경우와, quandl에서 가져오는 경우로 나뉜다.<jupyter_code>!pip install -q pandas_datareader # pandas_datareader 패키지를 인스톨 하는 코드이다.

import pandas_datareader.data as web
import datetime # 원하는 날짜를 형성하여 만들 수 가 있다.

start = datetime.datetime(2017, 10, 19)
end = datetime.datetime(2017, 11, 1)

aapl = web.DataReader('AAPL','google',start,end)
aapl
!pip install -q quandl # quandl 패키지를 인스톨 하는 코드이다.

import quandl

# qunadl.get(qunadl_data_code, periods, api_key) 
# quandl에서 데이터를 받는 코드는 데이터 코드, 기간, 회원가입시 발급받을 수 있는 개인 api_key로 이루어진다. [ https://www.quandl.com/ ]

data = quandl.get("BCHARTS/BITSTAMPUSD",start_date="2017-12-01", end_date="2017-12-31") # 이 데이터는 api_key가 필요없이 받아올 수 있다.
data

# Plot graph. Set title, xlabel, ylabel and xlim
type(data)
ax = data['Close'].plot()
ax.set_title('Title Here XXX')
ax.set_xlabel('xlabel Here YYY')
ax.set_ylabel('ylabel Here ZZZ')
# Simple Linear Regression: scipy, stats, linregress
from scipy import stats
slope, intercept, rvalue, pvalue, stderr = stats.linregress(data['Volume (BTC)'],data['Close'])
print(slope)
print(stderr)
print(slope/stderr)<jupyter_output>0.003256020572302811
0.04845960858779708
0.06719040180449848
{'fraction_non_alphanumeric': 0.1314717859220477, 'fraction_numerical': 0.057300756253635836, 'mean_word_length': 6.105371900826446, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '498646', 'license': 'MIT', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1525, 'n_words': 330, 'path': '02_Pandas.ipynb', 'repo_name': 'khbae/trading', 'size': '3438'}