経済指標の取得
行う処理は
カレンダーの予想時刻と
現在時刻
つまり date time が一緒になったら
Event で検索
とりあえず event 内容をリストに入れる
あと
Date time も格納する
Datetime に関しては
文字列から datetime に変換する
まずはリストにする
1 | value.tolist() |
でリスト変換可能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | events = economic_data[ "event" ] economic_event = events.values.tolist() #events=events[0] print (economic_event[ 0 ]) economic_events = "Chinese Industrial profit YTD (Feb)" test_event = economic_event[ 3 ] print (test_event) print (economic_events) economic_event |
これで
1 | economic_event |
へリストで格納できる
これを
1 | economic_data[economic_data[ 'event' ]. str .contains(economic_event[ 4 ])] |
というようにすれば検索できるが
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | Chinese Industrial profit YTD (Feb) Investing.com GBP / USD Index Chinese Industrial profit YTD (Feb) Out[ 78 ]: [ 'Chinese Industrial profit YTD (Feb)' , 'Finnish Consumer Confidence (Mar)' , 'Finnish Industrial Confidence (Mar)' , 'Investing.com GBP/USD Index' , 'Investing.com Gold Index' , 'Investing.com S&P 500 Index' , 'Investing.com USD/CAD Index' , 'Investing.com USD/CHF Index' , 'Investing.com AUD/USD Index' , 'Investing.com USD/JPY Index' , 'Investing.com NZD/USD Index' , 'Investing.com EUR/USD Index' , 'Trade Balance (Feb)' , 'Credit Indicator (YoY) (Feb)' , 'Core Retail Sales (MoM) (Feb)' , 'Lithuania Retail Sales (MoM)' , 'Lithuania Retail Sales (YoY)' , 'Gross Wages (YoY) (Jan)' , 'Exports (MoM) (Feb)' , 'Imports (MoM) (Feb)' , 'Trade Balance' , 'Irish Retail Sales (MoM) (Feb)' , 'Irish Retail Sales (YoY) (Feb)' , 'BoE Gov Bailey Speaks' , 'Quarterly Unemployment Rate' , 'M3 Money Supply (YoY) (Dec)' , 'Private Sector Loans (YoY) (Dec)' , 'BCB Focus Market Readout' , 'Greek Credit Expansion (YoY)' , 'Trade Balance (Feb)' , 'Trade Balance (USD) (Feb)' , 'GDP (YoY)' , 'GDP Quarterly' , 'Goods Trade Balance (Feb)' , 'Retail Inventories Ex Auto (Feb)' , 'Wholesale Inventories (MoM)' , 'Current Account (USD) (Feb)' , 'Foreign direct investment (USD) (Feb)' , 'French 12-Month BTF Auction' , 'French 3-Month BTF Auction' , 'French 6-Month BTF Auction' , 'Dallas Fed Mfg Business Index (Mar)' ] |
の中で
1 | Chinese Industrial profit YTD (Feb) |
というように
(Feb)
があるとエラーになる
他の指標も試したけど
()があるものは全てエラーになる
この場合エスケープさせるか
(以降は削除するしかない
Macのキーボードの「Option」と
右上にある「¥マーク」を同時に押しすると
入力ソースが英数であろうと、
ひらがなであろうと
半角のバックスラッシュ(「\」)が入力される
Option + ¥
でバックスラッシュの\\ 2つで
エスケープできるので
1 | economic_data[economic_data[ 'event' ]. str .contains( "Exports \\(MoM\\) " )] |
としたらエラーがなくなった
つまりリストの中で()のある部分をエスケープしないとだめ
これは
Replace でできるので
1 | economic_event.replace( '(' , '\\(' ) |
としたけど
すでにリストにしてしまうとだめ
1 2 3 | events = economic_data[ "event" ]. str .replace( '(' , '\(' ). str .replace( ')' , '\)' ) events |
とすれば
1 2 3 | / var / folders / db / tkl5w9dd3kn3h53ctyl4s6180000gn / T / ipykernel_8436 / 2811222662.py : 4 : FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will * not * be treated as literal strings when regex = True . events = economic_data[ "event" ]. str .replace( '(' , '\(' ). str .replace( ')' , '\)' ) |
とエラーは出るけど変換はできる
あとは
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | economic_event = events.values.tolist() #events=events[0] print (economic_event[ 0 ]) economic_events = "Chinese Industrial profit YTD (Feb)" test_event = economic_event[ 3 ] print (test_event) print (economic_events) print (economic_event) |
でリストにできるので
1 | economic_data[economic_data[ 'event' ]. str .contains(economic_event[ 4 ])] |
とすれば検索条件に当てはめることも可能