<jupyter_start><jupyter_text>list 두개를 합치기<jupyter_code>list1 = [{"date_time":"2020-02-27T23:00:00",  "price":1000, "kind": 1}, 
  {"date_time":"2020-02-27T23:00:00",  "price":1000, "kind": 0},
  {"date_time":"2020-02-27T23:00:00",  "price":1000, "kind": 2}
]

list2 = [{"date_time":"2020-02-27T23:02:00",  "price":1000, "kind": 0},
  {"date_time":"2020-02-27T23:01:00",  "price":1000, "kind": 1},
  {"date_time":"2020-02-27T23:01:00",  "price":1000, "kind": 0}
]

total = list1 + list2
total<jupyter_output><empty_output><jupyter_text>list를 sorted 함수를 이용해서 date_time 기준으로 정렬<jupyter_code>from datetime import datetime
sorted_total = sorted(
  total,
  key=lambda x: datetime.strptime(x["date_time"], "%Y-%m-%dT%H:%M:%S")
)
sorted_total<jupyter_output><empty_output><jupyter_text>list를 sorted함수를 이용해서 date_time과 kind를 기준으로 정렬<jupyter_code>sorted_total = sorted(
    total,
    key=lambda x: (
        datetime.strptime(x["date_time"], "%Y-%m-%dT%H:%M:%S"),
        x["kind"],
    ),
)
sorted_total<jupyter_output><empty_output><jupyter_text>캔들 그래프 연습을 위한 더미 데이터<jupyter_code>dummy_info_list = [
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:50:00',
  'opening_price': 10591000.0,
  'high_price': 10605000.0,
  'low_price': 10591000.0,
  'closing_price': 10605000.0,
  'acc_price': 116316536.37072,
  'acc_volume': 10.97288124,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:51:00',
  'opening_price': 10608000.0,
  'high_price': 10611000.0,
  'low_price': 10596000.0,
  'closing_price': 10598000.0,
  'acc_price': 132749879.7377,
  'acc_volume': 12.52234496,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:52:00',
  'opening_price': 10598000.0,
  'high_price': 10611000.0,
  'low_price': 10596000.0,
  'closing_price': 10611000.0,
  'acc_price': 59612254.02454,
  'acc_volume': 5.6232814,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:53:00',
  'opening_price': 10612000.0,
  'high_price': 10622000.0,
  'low_price': 10612000.0,
  'closing_price': 10622000.0,
  'acc_price': 50830798.21126,
  'acc_volume': 4.78835739,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:54:00',
  'opening_price': 10617000.0,
  'high_price': 10630000.0,
  'low_price': 10617000.0,
  'closing_price': 10630000.0,
  'acc_price': 82005173.84158,
  'acc_volume': 7.71635194,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:55:00',
  'opening_price': 10630000.0,
  'high_price': 10650000.0,
  'low_price': 10630000.0,
  'closing_price': 10650000.0,
  'acc_price': 99752483.10131,
  'acc_volume': 9.37410465,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:56:00',
  'opening_price': 10646000.0,
  'high_price': 10657000.0,
  'low_price': 10646000.0,
  'closing_price': 10646000.0,
  'acc_price': 328379382.72467,
  'acc_volume': 30.83367158,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:57:00',
  'opening_price': 10646000.0,
  'high_price': 10650000.0,
  'low_price': 10645000.0,
  'closing_price': 10647000.0,
  'acc_price': 51564466.13633,
  'acc_volume': 4.84241397,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:58:00',
  'opening_price': 10646000.0,
  'high_price': 10669000.0,
  'low_price': 10646000.0,
  'closing_price': 10669000.0,
  'acc_price': 197890470.89159,
  'acc_volume': 18.56679051,
  'kind': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T05:59:00',
  'opening_price': 10669000.0,
  'high_price': 10671000.0,
  'low_price': 10666000.0,
  'closing_price': 10670000.0,
  'acc_price': 106676249.34666,
  'acc_volume': 9.99976792,
  'kind': 0}
]<jupyter_output><empty_output><jupyter_text>dummy_info_list로 DataFrame을 만들고 키값을 변경<jupyter_code>import pandas as pd
total = pd.DataFrame(dummy_info_list)
total = total.rename(
  columns={
      "date_time": "Date",
      "opening_price": "Open",
      "high_price": "High",
      "low_price": "Low",
      "closing_price": "Close",
      "acc_volume": "Volume",
  }
)
total<jupyter_output><empty_output><jupyter_text>Data 컬럼을 인덱스로 설정하고 datetime 객체로 만들어준다<jupyter_code>total = total.set_index("Date")
total.index = pd.to_datetime(total.index)
total<jupyter_output><empty_output><jupyter_text>DataFrame을 이용해서 캔들그래프를 그린다<jupyter_code>import mplfinance as mpf
mpf.plot(total, type="candle", volume=True, style="starsandstripes")<jupyter_output><empty_output><jupyter_text>Test용 total list, 추가 그래프를 그리기 위한 데이터가 추가된 리스트<jupyter_code>total_list = [{'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:05:00',
  'opening_price': 10563000.0,
  'high_price': 10571000.0,
  'low_price': 10553000.0,
  'closing_price': 10570000.0,
  'acc_price': 125016880.36179,
  'acc_volume': 11.83838866,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:06:00',
  'opening_price': 10569000.0,
  'high_price': 10569000.0,
  'low_price': 10525000.0,
  'closing_price': 10541000.0,
  'acc_price': 170233795.53858,
  'acc_volume': 16.13286781,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:07:00',
  'opening_price': 10543000.0,
  'high_price': 10554000.0,
  'low_price': 10525000.0,
  'closing_price': 10551000.0,
  'acc_price': 117197604.53511,
  'acc_volume': 11.12671815,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:08:00',
  'opening_price': 10544000.0,
  'high_price': 10571000.0,
  'low_price': 10542000.0,
  'closing_price': 10553000.0,
  'acc_price': 160541193.29183,
  'acc_volume': 15.21643098,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:09:00',
  'opening_price': 10553000.0,
  'high_price': 10571000.0,
  'low_price': 10553000.0,
  'closing_price': 10570000.0,
  'acc_price': 24123712.32792,
  'acc_volume': 2.28315364,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:10:00',
  'opening_price': 10570000.0,
  'high_price': 10583000.0,
  'low_price': 10561000.0,
  'closing_price': 10576000.0,
  'acc_price': 55884451.39599,
  'acc_volume': 5.28528135,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:11:00',
  'opening_price': 10584000.0,
  'high_price': 10668000.0,
  'low_price': 10584000.0,
  'closing_price': 10619000.0,
  'acc_price': 248089440.31111,
  'acc_volume': 23.380787,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:12:00',
  'opening_price': 10641000.0,
  'high_price': 10641000.0,
  'low_price': 10620000.0,
  'closing_price': 10627000.0,
  'acc_price': 106095669.19354,
  'acc_volume': 9.97880594,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:13:00',
  'opening_price': 10624000.0,
  'high_price': 10624000.0,
  'low_price': 10588000.0,
  'closing_price': 10611000.0,
  'acc_price': 79892387.53559,
  'acc_volume': 7.53610537,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:14:00',
  'opening_price': 10611000.0,
  'high_price': 10617000.0,
  'low_price': 10611000.0,
  'closing_price': 10612000.0,
  'acc_price': 31435566.052,
  'acc_volume': 2.96176369,
  'kind': 0,
  'return': 0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:15:00',
  'opening_price': 10617000.0,
  'high_price': 10640000.0,
  'low_price': 10616000.0,
  'closing_price': 10640000.0,
  'acc_price': 71021259.56352,
  'acc_volume': 6.67818262,
  'kind': 0,
  'buy': 10640000.0,
  'return': -0.221,
  'avr_price': 10640000.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:16:00',
  'opening_price': 10640000.0,
  'high_price': 10640000.0,
  'low_price': 10554000.0,
  'closing_price': 10574000.0,
  'acc_price': 213694042.37772,
  'acc_volume': 20.16705026,
  'kind': 0,
  'buy': 10574000.0,
  'return': 0.073,
  'avr_price': 10607000.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:17:00',
  'opening_price': 10574000.0,
  'high_price': 10624000.0,
  'low_price': 10574000.0,
  'closing_price': 10624000.0,
  'acc_price': 27553306.72052,
  'acc_volume': 2.60075435,
  'kind': 0,
  'buy': 10624000.0,
  'return': -0.204,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:18:00',
  'opening_price': 10595000.0,
  'high_price': 10614000.0,
  'low_price': 10595000.0,
  'closing_price': 10596000.0,
  'acc_price': 21217229.84691,
  'acc_volume': 1.99925902,
  'kind': 0,
  'return': -0.204,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:19:00',
  'opening_price': 10597000.0,
  'high_price': 10613000.0,
  'low_price': 10576000.0,
  'closing_price': 10576000.0,
  'acc_price': 78719024.01547,
  'acc_volume': 7.4309397,
  'kind': 0,
  'return': -0.39,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:20:00',
  'opening_price': 10590000.0,
  'high_price': 10595000.0,
  'low_price': 10584000.0,
  'closing_price': 10584000.0,
  'acc_price': 46789949.09722,
  'acc_volume': 4.41728984,
  'kind': 0,
  'return': -0.39,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:21:00',
  'opening_price': 10584000.0,
  'high_price': 10594000.0,
  'low_price': 10584000.0,
  'closing_price': 10587000.0,
  'acc_price': 12627442.26131,
  'acc_volume': 1.19234456,
  'kind': 0,
  'return': -0.288,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:22:00',
  'opening_price': 10587000.0,
  'high_price': 10594000.0,
  'low_price': 10587000.0,
  'closing_price': 10590000.0,
  'acc_price': 24121732.49702,
  'acc_volume': 2.27779416,
  'kind': 0,
  'sell': 10590000.0,
  'return': -0.239,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:23:00',
  'opening_price': 10590000.0,
  'high_price': 10596000.0,
  'low_price': 10588000.0,
  'closing_price': 10596000.0,
  'acc_price': 33316167.48592,
  'acc_volume': 3.14566627,
  'kind': 0,
  'sell': 10596000.0,
  'return': -0.259,
  'avr_price': 10612667.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:24:00',
  'opening_price': 10596000.0,
  'high_price': 10605000.0,
  'low_price': 10592000.0,
  'closing_price': 10595000.0,
  'acc_price': 37003507.91232,
  'acc_volume': 3.49285543,
  'kind': 0,
  'buy': 10595000.0,
  'return': -0.28,
  'avr_price': 10605532.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:25:00',
  'opening_price': 10595000.0,
  'high_price': 10605000.0,
  'low_price': 10592000.0,
  'closing_price': 10593000.0,
  'acc_price': 89250545.82747,
  'acc_volume': 8.42271859,
  'kind': 0,
  'buy': 10593000.0,
  'return': -0.284,
  'avr_price': 10601927.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:26:00',
  'opening_price': 10593000.0,
  'high_price': 10601000.0,
  'low_price': 10593000.0,
  'closing_price': 10594000.0,
  'acc_price': 29726922.48995,
  'acc_volume': 2.80622472,
  'kind': 0,
  'buy': 10594000.0,
  'return': -0.145,
  'avr_price': 10600156.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:27:00',
  'opening_price': 10594000.0,
  'high_price': 10610000.0,
  'low_price': 10594000.0,
  'closing_price': 10610000.0,
  'acc_price': 69240309.12415,
  'acc_volume': 6.53106483,
  'kind': 0,
  'return': -0.145,
  'avr_price': 10600156.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:28:00',
  'opening_price': 10610000.0,
  'high_price': 10610000.0,
  'low_price': 10593000.0,
  'closing_price': 10594000.0,
  'acc_price': 124335516.63124,
  'acc_volume': 11.72878474,
  'kind': 0,
  'sell': 10594000.0,
  'return': -0.224,
  'avr_price': 10600156.0},
 {'market': 'KRW-BTC',
  'date_time': '2020-04-30T06:29:00',
  'opening_price': 10595000.0,
  'high_price': 10608000.0,
  'low_price': 10595000.0,
  'closing_price': 10608000.0,
  'acc_price': 40680534.44281,
  'acc_volume': 3.83602971,
  'kind': 0,
  'return': -0.224,
  'avr_price': 10600156.0}]<jupyter_output><empty_output><jupyter_text>dummy_info_list로 DataFrame을 만들고 키값을 변경<jupyter_code>import pandas as pd
total = pd.DataFrame(total_list)
total = total.rename(
  columns={
      "date_time": "Date",
      "opening_price": "Open",
      "high_price": "High",
      "low_price": "Low",
      "closing_price": "Close",
      "acc_volume": "Volume",
  }
)
total<jupyter_output><empty_output><jupyter_text>Data 컬럼을 인덱스로 설정하고 datetime 객체로 만들어준다<jupyter_code>total = total.set_index("Date")
total.index = pd.to_datetime(total.index)
total<jupyter_output><empty_output><jupyter_text>DataFrame을 이용해서 캔들그래프를 그린다<jupyter_code>import mplfinance as mpf
mpf.plot(total, type="candle", volume=True, style="starsandstripes")<jupyter_output><empty_output><jupyter_text>추가 그래프가 포함된 그래프를 그린다<jupyter_code>apds = [
    mpf.make_addplot(total["buy"], type="scatter", markersize=100, marker="^"),
    mpf.make_addplot(total["sell"], type="scatter", markersize=100, marker="v"),
    mpf.make_addplot(total["avr_price"]),
    mpf.make_addplot((total["return"]), panel=1, color="g", secondary_y=True)
]

mpf.plot(
    total,
    type="candle",
    volume=True,
    addplot=apds,
    style="starsandstripes",
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2014150580635238, 'fraction_numerical': 0.2291778820272245, 'mean_word_length': 4.876186172616358, 'pattern_counts': {'":': 30, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '269663', 'license': 'MIT', 'n_tokens_mistral': 8083, 'n_tokens_neox': 6164, 'n_words': 920, 'path': 'notebook/analyzer_exercise.ipynb', 'repo_name': 'hoondental/smtm', 'size': '13003'}