環境
window10 home
python3
アナコンダ3のジュピターノートブックを使用
pythonでpandasを使ってエクセル(CSV)ファイルを読み込んだ後そのファイルの
最初の行の日時・始値列内の最初の行の値・高値列内の最大値・安値列内の最小値・終値列内の最後の行の値
を取り出してcsvファイルを作り出し保存するプログラムを作ったのですが
何故か最初に書いた4行だけ保存されていません
python
1import pandas as pd 2 3#csvを読み込ませる 4a=pd.read_csv(r"Desktop\FX\原本\ユロドル\08\EURUSD_20080103.csv",encoding="shift-jis") 5 6#作ったリストをhour_barに入れデータフレームにしてファイルを保存 7cols=["日時","Open","High","Low","Close"] 8hour_bar=pd.DataFrame(index=[], columns=cols) 9hour_bar["日時"]=pd.to_datetime(str(a["日時"][0])[:8]) 10hour_bar["Open"]=a["始値"][0] 11hour_bar["High"]=a["高値"].max() 12hour_bar["Low"]=a["安値"].min() 13hour_bar["Close"]=a["終値"].tail(1) 14print(hour_bar) 15hour_bar.to_csv(r"Desktop\FX\テスト足\08年日足\20080103.csv", encoding="shift-jis", index=False)
これを実行するとprint(hour_bar)の部分で確認できますが
Closeの終値のみが代入されていて他の日時・open・High・Lowは何故か代入されていません
更に不可解なのがこの代入作業を下記の様に2回連続でやらせると普通に書き込まれています
python
1import pandas as pd 2 3#csvを読み込ませる 4a=pd.read_csv(r"Desktop\FX\原本\ユロドル\08\EURUSD_20080103.csv",encoding="shift-jis") 5 6#作ったリストをhour_barに入れデータフレームにしてファイルを保存 7cols=["日時","Open","High","Low","Close"] 8hour_bar=pd.DataFrame(index=[], columns=cols) 9hour_bar["日時"]=pd.to_datetime(str(a["日時"][0])[:8]) 10hour_bar["Open"]=a["始値"][0] 11hour_bar["High"]=a["高値"].max() 12hour_bar["Low"]=a["安値"].min() 13hour_bar["Close"]=a["終値"].tail(1) 14hour_bar["日時"]=pd.to_datetime(str(a["日時"][0])[:8]) 15hour_bar["Open"]=a["始値"][0] 16hour_bar["High"]=a["高値"].max() 17hour_bar["Low"]=a["安値"].min() 18hour_bar["Close"]=a["終値"].tail(1) 19print(hour_bar) 20hour_bar.to_csv(r"Desktop\FX\テスト足\08年日足\20080103.csv", encoding="shift-jis", index=False)
これは一体どういう事なのでしょうか?
※読み込んだCSVファイルは一部省略してますが下記です
|日時 始値 高値 安値 終値
20080103070000 1.4711 1.4714 1.4711 1.4713
20080103070100 1.4713 1.4714 1.4712 1.4712
20080103070200 1.4712 1.4714 1.471 1.4714
20080103070300 1.4714 1.4715 1.4714 1.4714
20080103070400 1.4714 1.4715 1.4713 1.4714
20080103070500 1.4714 1.4715 1.4713 1.4713
20080103070600 1.4713 1.4713 1.4711 1.4712
20080103070700 1.4712 1.4713 1.4712 1.4712
20080103070800 1.4712 1.4713 1.4712 1.4713
20080103070900 1.4713 1.4715 1.4712 1.4715
20080103071000 1.4716 1.472 1.4716 1.4719
20080103071100 1.4719 1.4719 1.4718 1.4718
20080103071200 1.4718 1.4719 1.4715 1.4718
20080103071300 1.4717 1.4718 1.4715 1.4715
20080103071400 1.4715 1.4716 1.4711 1.4713
20080103071500 1.4713 1.4713 1.471 1.4711
20080103071600 1.4711 1.4712 1.4711 1.4711
20080103071700 1.4711 1.4713 1.4711 1.4712
20080103071800 1.4713 1.4713 1.4713 1.4713
20080103071900 1.4713 1.4716 1.4713 1.4714
20080103072000 1.4714 1.4715 1.4712 1.4712
20080103072100 1.4712 1.4712 1.4711 1.4712
20080103072200 1.4712 1.4712 1.471 1.4711
20080103072300 1.4711 1.4713 1.4711 1.4713
20080103072400 1.4713 1.4713 1.471 1.4712
20080103072500 1.4712 1.4714 1.4712 1.4714
20080103072600 1.4714 1.4714 1.4714 1.4714
20080103072700 1.4714 1.4714 1.4714 1.4714
20080103072800 1.4714 1.4714 1.4714 1.4714
20080103072900 1.4714 1.4714 1.4714 1.4714
20080103073000 1.4714 1.4714 1.4713 1.4713
20080103073100 1.4713 1.4714 1.4711 1.4714
20080103073200 1.4714 1.4716 1.4711 1.4716
20080103073300 1.4716 1.472 1.4716 1.4717
20080103073400 1.4717 1.4722 1.4717 1.4717
20080103073500 1.4717 1.4722 1.4717 1.4722
20080103073600 1.4722 1.4722 1.4721 1.4721
20080103073700 1.4721 1.4721 1.4717 1.4719
20080103073800 1.4719 1.472 1.4717 1.4719
20080103073900 1.4719 1.4719 1.4714 1.4715
20080103074000 1.4715 1.4715 1.4715 1.4715
20080103074100 1.4716 1.4716 1.4716 1.4716
20080103074200 1.4716 1.4716 1.4714 1.4715
20080103074300 1.4715 1.4716 1.4715 1.4716
20080103074400 1.4716 1.4717 1.4716 1.4716
20080103074500 1.4716 1.4717 1.4716 1.4717
20080103074600 1.4717 1.4717 1.4717 1.4717
20080103074700 1.4717 1.4717 1.4717 1.4717
20080103074800 1.4717 1.4717 1.4717 1.4717
20080103074900 1.4717 1.4717 1.4717 1.4717
20080103075000 1.4717 1.4718 1.4717 1.4717
20080103075100 1.4717 1.472 1.4717 1.4719
20080103075200 1.4719 1.4719 1.4718 1.4718
20080103075300 1.4719 1.4719 1.4719 1.4719
20080103075400 1.4719 1.4719 1.4719 1.4719
20080103075500 1.4719 1.4719 1.4719 1.4719
20080103075600 1.4719 1.4721 1.4719 1.4719
20080103075700 1.472 1.4721 1.4719 1.472
20080103075800 1.472 1.472 1.472 1.472
20080103075900 1.472 1.472 1.472 1.472
20080103080000 1.472 1.4721 1.472 1.4721
20080103080100 1.4721 1.4723 1.4721 1.4723
20080103080200 1.4722 1.4722 1.4721 1.4722
20080103080300 1.4722 1.4722 1.4721 1.4721
20080103080400 1.4721 1.4721 1.4721 1.4721
20080103080500 1.4721 1.4721 1.4721 1.4721
20080103080600 1.4721 1.4721 1.472 1.472
20080103080700 1.472 1.4721 1.472 1.4721
20080103080800 1.4721 1.4722 1.4721 1.4721
20080103080900 1.4721 1.4721 1.4719 1.472
20080103081000 1.472 1.472 1.4719 1.472
20080103081100 1.472 1.472 1.4719 1.4719
20080103081200 1.4719 1.4721 1.4719 1.472
20080103081300 1.472 1.4721 1.472 1.4721
20080103081400 1.4721 1.4721 1.472 1.472
20080103081500 1.472 1.472 1.472 1.472
20080103081600 1.472 1.4722 1.472 1.472
20080103081700 1.472 1.4723 1.472 1.4723
20080103081800 1.4723 1.4725 1.4723 1.4723
20080103081900 1.4723 1.4723 1.4719 1.472
20080103082000 1.472 1.4721 1.472 1.4721
20080103082100 1.4721 1.4721 1.472 1.4721
20080103082200 1.4721 1.4723 1.4721 1.4721
20080103082300 1.4721 1.4722 1.4721 1.4721
20080103082400 1.4722 1.4722 1.4721 1.4722
20080103082500 1.4722 1.4722 1.472 1.4721
20080103082600 1.4721 1.4721 1.4721 1.4721
20080103082700 1.4721 1.4721 1.472 1.4721
20080103082800 1.4721 1.4721 1.4721 1.4721
20080103082900 1.4721 1.4724 1.4721 1.4722
20080103083000 1.4722 1.4724 1.4722 1.4723
20080103083100 1.4723 1.4723 1.4722 1.4722
20080103083200 1.4722 1.4723 1.4722 1.4723
20080103083300 1.4723 1.4724 1.4721 1.4722
20080103083400 1.4722 1.4723 1.4722 1.4722
20080103083500 1.4722 1.4723 1.472 1.4722
20080103083600 1.4722 1.4722 1.4721 1.4721
20080103083700 1.4721 1.4722 1.472 1.4721
20080103083800 1.4721 1.4721 1.4716 1.4717
20080103083900 1.4717 1.4717 1.4714 1.4716
20080103084000 1.4716 1.4719 1.4716 1.4718
20080103084100 1.4718 1.4718 1.4716 1.4716
20080103084200 1.4716 1.4716 1.4711 1.4713
20080103084300 1.4713 1.4715 1.4712 1.4714
20080103084400 1.4714 1.4714 1.4711 1.4711
20080103084500 1.4711 1.4713 1.4711 1.4713
20080103084600 1.4713 1.4714 1.4711 1.4714
20080103084700 1.4714 1.4716 1.4712 1.4716
20080103084800 1.4716 1.4718 1.4716 1.4717
20080103084900 1.4717 1.472 1.4717 1.4719
20080103085000 1.4719 1.472 1.4716 1.4717
20080103085100 1.4717 1.4719 1.4717 1.4719
20080103085200 1.4719 1.4719 1.4717 1.4719
20080103085300 1.4719 1.4721 1.4718 1.4719
20080103085400 1.4719 1.4719 1.4718 1.4719
20080103085500 1.4719 1.4722 1.4719 1.4722
20080103085600 1.4722 1.4722 1.4718 1.4718
20080103085700 1.4717 1.4717 1.4714 1.4714
20080103085800 1.4714 1.4715 1.4712 1.4714
20080103085900 1.4714 1.4715 1.4714 1.4715
20080103090000 1.4715 1.4716 1.4714 1.4714
20080104060100 1.4749 1.4749 1.4749 1.4749
20080104060200 1.4749 1.4749 1.4748 1.4749
20080104060300 1.4749 1.475 1.4749 1.475
20080104060400 1.475 1.475 1.4749 1.4749
20080104060500 1.4749 1.475 1.4749 1.475
20080104060600 1.475 1.475 1.4749 1.475
20080104060700 1.475 1.475 1.4748 1.4749
20080104060800 1.4749 1.4749 1.4748 1.4748
20080104060900 1.4748 1.4748 1.4747 1.4747
20080104061000 1.4747 1.4748 1.4746 1.4746
20080104061100 1.4746 1.4746 1.4743 1.4743
20080104061200 1.4743 1.4745 1.4743 1.4745
20080104061300 1.4745 1.4746 1.4744 1.4746
20080104061400 1.4746 1.4746 1.4745 1.4745
20080104061500 1.4746 1.4746 1.4745 1.4746
20080104061600 1.4746 1.4747 1.4745 1.4747
20080104061700 1.4747 1.4747 1.4746 1.4746
20080104061800 1.4746 1.4746 1.4745 1.4745
20080104061900 1.4745 1.4747 1.4745 1.4745
20080104062000 1.4745 1.4746 1.4745 1.4745
20080104062100 1.4745 1.4747 1.4745 1.4747
20080104062200 1.4747 1.4747 1.4746 1.4747
20080104062300 1.4747 1.4747 1.4747 1.4747
20080104062400 1.4747 1.4747 1.4747 1.4747
20080104062500 1.4747 1.4747 1.4745 1.4745
20080104062600 1.4745 1.4745 1.4744 1.4744
20080104062700 1.4744 1.4744 1.4742 1.4743
20080104062800 1.4743 1.4743 1.4743 1.4743
20080104062900 1.4743 1.4744 1.4743 1.4743
20080104063000 1.4743 1.4744 1.4743 1.4744
20080104063100 1.4743 1.4743 1.4743 1.4743
20080104063200 1.4743 1.4743 1.4743 1.4743
20080104063300 1.4743 1.4744 1.4743 1.4743
20080104063400 1.4744 1.4744 1.4743 1.4743
20080104063500 1.4743 1.4744 1.4743 1.4744
20080104063600 1.4744 1.4745 1.4744 1.4745
20080104063700 1.4745 1.4745 1.4745 1.4745
20080104063800 1.4745 1.4745 1.4745 1.4745
20080104063900 1.4745 1.4745 1.4744 1.4745
20080104064000 1.4745 1.4746 1.4745 1.4746
20080104064100 1.4746 1.4746 1.4745 1.4745
20080104064200 1.4745 1.4745 1.4745 1.4745
20080104064300 1.4745 1.4745 1.4745 1.4745
20080104064400 1.4745 1.4746 1.4743 1.4744
20080104064500 1.4744 1.4744 1.4743 1.4743
20080104064600 1.4743 1.4744 1.4743 1.4743
20080104064700 1.4743 1.4745 1.4743 1.4744
20080104064800 1.4744 1.4745 1.4744 1.4745
20080104064900 1.4745 1.4746 1.4745 1.4746
20080104065000 1.4746 1.4746 1.4744 1.4744
20080104065100 1.4744 1.4745 1.4743 1.4744
20080104065200 1.4744 1.4745 1.4744 1.4744
20080104065300 1.4744 1.4746 1.4743 1.4745
20080104065400 1.4745 1.4745 1.4743 1.4744
20080104065500 1.4745 1.4746 1.4744 1.4746
20080104065600 1.4746 1.4746 1.4745 1.4746
20080104065700 1.4746 1.4746 1.4744 1.4745
20080104065800 1.4745 1.4746 1.4744 1.4744
20080104065900 1.4744 1.4748 1.4744 1.4748
||||
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/14 07:51