from pandas_datareader import data as pdr
import plotly.offline as py_offline
import plotly.graph_objs as go
import fix_yahoo_finance as yf
py_offline.init_notebook_mode(connected=True)
yf.pdr_override()
mcd = pdr.get_data_yahoo("MCD", start="2005-07-01", end="2005-07-31")
mcd_candle = go.Candlestick(x=mcd.index,
open=mcd.Open,
high=mcd.High,
low=mcd.Low,
close=mcd.Close,
increasing=dict(line=dict(color= '#00FF00')),
decreasing=dict(line=dict(color= '#FF0000'))
)
data = [mcd_candle]
layout = go.Layout(
plot_bgcolor='rgb(59,68,75)'
)
fig = go.Figure(data=data, layout=layout)
上面的代码段工作正常,但现在我想用我的实际数据替换mcd = pdr.get_data_yahoo("MCD", start="2005-07-01", end="2005-07-31")
,但我需要重新采样数据以获取开放,高,低和关闭数据。以下是我的CSV文件示例:
#=TimeAndSale,EventSymbol,EventTime,Time,Sequence,ExchangeCode,Price,Size,BidPrice,AskPrice,SaleConditions,Flags
TimeAndSale,AKER,20180402-070000.164-0400,20180402-070000-0400,162:2,Q,0.8998,1991,0.899,0.92,"@FT ",22604
TimeAndSale,AKER,20180402-070000.165-0400,20180402-070000-0400,162:4,Q,0.9,300,0.899,0.92,"@FT ",22604
TimeAndSale,AKER,20180402-070000.165-0400,20180402-070000-0400,162:6,Q,0.899,1000,0.899,0.92,"@FT ",22604
TimeAndSale,AKER,20180402-070000.165-0400,20180402-070000-0400,162:8,K,0.9,4000,0.9,0.92,"@ T ",8268
TimeAndSale,AKER,20180402-070150.608-0400,20180402-070150-0400,605:10,P,0.91,2000,0.905,0.92,"@ T ",8236
TimeAndSale,AKER,20180402-070521.770-0400,20180402-070521-0400,765:12,P,0.91,1000,0.9,0.91,"@FT ",22572
TimeAndSale,AKER,20180402-070527.239-0400,20180402-070527-0400,234:14,P,0.91,647,0.9,0.91,"@FT ",22572
TimeAndSale,AKER,20180402-070558.330-0400,20180402-070558-0400,325:15,K,0.92,30,0.91,0.92,"@ TI",8232
TimeAndSale,AKER,20180402-070643.959-0400,20180402-070643-0400,953:17,K,0.92,4470,0.92,0.925,"@ T ",8268
TimeAndSale,AKER,20180402-070809.017-0400,20180402-070809-0400,11:19,P,0.925,1985,0.91,0.925,"@FT ",22572
TimeAndSale,AKER,20180402-071030.623-0400,20180402-071030-0400,622:21,P,0.92,2000,0.92,0.925,"@ T ",8268
TimeAndSale,AKER,20180402-071140.207-0400,20180402-071140-0400,206:23,P,0.92,2073,0.92,0.925,"@ T ",8268
TimeAndSale,AKER,20180402-071203.431-0400,20180402-071203-0400,430:25,P,0.92,1000,0.92,0.925,"@ T ",8268
TimeAndSale,AKER,20180402-071204.798-0400,20180402-071204-0400,797:27,P,0.92,700,0.915,0.925,"@ T ",8268
TimeAndSale,AKER,20180402-071255.654-0400,20180402-071255-0400,652:28,P,0.92,80,0.918,0.925,"@ TI",8264
TimeAndSale,AKER,20180402-071601.928-0400,20180402-071601-0400,926:30,P,0.92,535,0.91,0.92,"@ T ",8236
TimeAndSale,AKER,20180402-071616.591-0400,20180402-071616-0400,589:32,P,0.92,885,0.91,0.92,"@FT ",22572
TimeAndSale,AKER,20180402-071616.591-0400,20180402-071616-0400,589:34,P,0.92,100,0.91,0.9337,"@FT ",22604
TimeAndSale,AKER,20180402-071616.591-0400,20180402-071616-0400,589:36,P,0.92,200,0.91,0.9337,"@FT ",22604
TimeAndSale,AKER,20180402-072605.196-0400,20180402-072605-0400,190:38,P,0.92,1815,0.92,0.93,"@ T ",8268
TimeAndSale,AKER,20180402-072605.196-0400,20180402-072605-0400,190:39,P,0.92,15,0.92,0.93,"@ TI",8264
TimeAndSale,AKER,20180402-072605.196-0400,20180402-072605-0400,190:41,P,0.92,1396,0.92,0.93,"@ T ",8268
TimeAndSale,AKER,20180402-072605.196-0400,20180402-072605-0400,190:43,P,0.92,774,0.92,0.93,"@ T ",8268
TimeAndSale,AKER,20180402-072606.057-0400,20180402-072606-0400,51:45,P,0.92,2226,0.905,0.92,"@ T ",8268
TimeAndSale,AKER,20180402-073317.446-0400,20180402-073317-0400,438:47,P,0.92,1000,0.905,0.92,"@FT ",22572
TimeAndSale,AKER,20180402-073701.182-0400,20180402-073701-0400,171:49,P,0.92,1000,0.905,0.92,"@ T ",8236
TimeAndSale,AKER,20180402-074033.896-0400,20180402-074033-0400,886:51,Q,0.905,4974,0.9,0.92,"@ T ",8268
TimeAndSale,AKER,20180402-074232.512-0400,20180402-074232-0400,501:52,Q,0.905,26,0.9,0.92,@FTI,22600
TimeAndSale,AKER,20180402-074232.522-0400,20180402-074232-0400,511:54,K,0.9,209,0.9,0.92,"@FT ",22604
TimeAndSale,AKER,20180402-074232.522-0400,20180402-074232-0400,511:56,P,0.9,350,0.9,0.92,"@FT ",22604
TimeAndSale,AKER,20180402-074259.372-0400,20180402-074259-0400,360:58,P,0.9,1415,0.83,0.92,"@FT ",22572
TimeAndSale,AKER,20180402-074351.411-0400,20180402-074351-0400,399:60,K,0.9,318,0.875,0.91,"@FT ",22572
TimeAndSale,AKER,20180402-074755.025-0400,20180402-074755-0400,17:62,Q,0.86,5000,0.831,0.9,"@FT ",22604
TimeAndSale,AKER,20180402-075015.457-0400,20180402-075015-0400,448:64,Q,0.86,100,0.8351,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075015.457-0400,20180402-075015-0400,448:66,Q,0.86,100,0.8351,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075015.457-0400,20180402-075015-0400,448:68,P,0.86,100,0.8351,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075107.641-0400,20180402-075107-0400,631:70,Q,0.86,100,0.8351,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:72,Q,0.86,100,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:74,Q,0.86,3200,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:76,Q,0.86,100,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:78,Q,0.86,4700,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:80,Q,0.86,1800,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.862-0400,20180402-075232-0400,852:82,Q,0.86,2155,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.863-0400,20180402-075232-0400,852:84,P,0.86,2600,0.8369,0.86,"@FT ",22572
TimeAndSale,AKER,20180402-075232.863-0400,20180402-075232-0400,853:86,Q,0.86,2745,0.8369,0.88,"@FT ",22572
TimeAndSale,AKER,20180402-080001.518-0400,20180402-074026-0400,327:88,D,0.92,103,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080003.171-0400,20180402-075525-0400,709:90,D,0.88,2000,0.8701,0.89,"@ T ",8268
TimeAndSale,AKER,20180402-080003.174-0400,20180402-075643-0400,162:92,D,0.88,9900,0.8701,0.89,"@ T ",8268
TimeAndSale,AKER,20180402-080004.376-0400,20180402-080000-0400,232:94,D,0.89,10000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080004.958-0400,20180402-070001-0400,333:96,D,0.9,300,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080004.970-0400,20180402-070026-0400,524:98,D,0.92,5000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080004.990-0400,20180402-070745-0400,466:100,D,0.92,8000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080004.990-0400,20180402-070800-0400,804:102,D,0.92,596,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080004.997-0400,20180402-071547-0400,313:104,D,0.92,2000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080005.011-0400,20180402-073659-0400,937:106,D,0.905,5000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080005.020-0400,20180402-073849-0400,822:108,D,0.905,10000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080005.020-0400,20180402-073930-0400,651:110,D,0.905,10000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080005.020-0400,20180402-073800-0400,295:112,D,0.905,5000,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080005.025-0400,20180402-074755-0400,9:114,D,0.86,12300,0.8701,0.89,"@ T ",8268
TimeAndSale,AKER,20180402-080007.330-0400,20180402-071447-0400,23:116,D,0.91,2015,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080007.649-0400,20180402-072816-0400,810:118,D,0.92,800,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080009.765-0400,20180402-080009-0400,753:120,Q,0.89,900,0.8701,0.89,"@FT ",22572
TimeAndSale,AKER,20180402-080009.765-0400,20180402-080009-0400,753:122,Q,0.89,100,0.8701,0.89,"@FT ",22572
TimeAndSale,AKER,20180402-080009.774-0400,20180402-080009-0400,755:124,D,0.89,1150,0.8701,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-080202.834-0400,20180402-080202-0400,817:126,D,0.9,16666,0.8701,0.9,"@ T ",8236
TimeAndSale,AKER,20180402-080338.197-0400,20180402-080338-0400,182:128,K,0.89,500,0.89,0.9,"@FT ",22604
TimeAndSale,AKER,20180402-080514.740-0400,20180402-080514-0400,732:130,D,0.89,3000,0.89,0.9,"@ T ",8268
TimeAndSale,AKER,20180402-080522.208-0400,20180402-080522-0400,203:132,Q,0.9,182,0.89,0.9,"@FT ",22572
TimeAndSale,AKER,20180402-080522.208-0400,20180402-080522-0400,203:134,Q,0.9,500,0.89,0.9,"@FT ",22572
TimeAndSale,AKER,20180402-080522.208-0400,20180402-080522-0400,203:136,Q,0.9,318,0.89,0.9,"@FT ",22572
TimeAndSale,AKER,20180402-080539.519-0400,20180402-080539-0400,514:138,K,0.89,700,0.89,0.9,"@FT ",22604
TimeAndSale,AKER,20180402-080610.713-0400,20180402-080610-0400,706:140,D,0.895,1000,0.89,0.895,"@ T ",8236
TimeAndSale,AKER,20180402-080629.881-0400,20180402-080629-0400,876:142,K,0.89,700,0.89,0.895,"@FT ",22604
TimeAndSale,AKER,20180402-080932.865-0400,20180402-080932-0400,854:143,D,0.895,65,0.89,0.895,"@ TI",8232
TimeAndSale,AKER,20180402-081234.923-0400,20180402-081234-0400,910:145,D,0.9,100,0.89,0.9,"@ T ",8236
TimeAndSale,AKER,20180402-081408.875-0400,20180402-081408-0400,865:147,Q,0.9,500,0.89,0.9,"@ T ",8236
TimeAndSale,AKER,20180402-081408.875-0400,20180402-081408-0400,865:149,Q,0.9,1053,0.89,0.9,"@ T ",8236
TimeAndSale,AKER,20180402-081744.093-0400,20180402-081744-0400,77:151,D,0.899,580,0.89,0.899,"@ T ",8236
TimeAndSale,AKER,20180402-081829.771-0400,20180402-081829-0400,758:153,K,0.89,240,0.88,0.895,"@ T ",8236
TimeAndSale,AKER,20180402-081936.390-0400,20180402-081936-0400,373:155,D,0.88,4500,0.88,0.89,"@ T ",8268
TimeAndSale,AKER,20180402-082127.575-0400,20180402-082127-0400,556:156,D,0.89,30,0.88,0.89,"@ TI",8232
TimeAndSale,AKER,20180402-082252.003-0400,20180402-082251-0400,987:158,K,0.88,1501,0.88,0.89,"@FT ",22604
TimeAndSale,AKER,20180402-082327.963-0400,20180402-082327-0400,943:160,D,0.88,999,0.861,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-082558.488-0400,20180402-082558-0400,466:162,D,0.88,2501,0.861,0.89,"@ T ",8236
TimeAndSale,AKER,20180402-083223.876-0400,20180402-083223-0400,839:164,D,0.861,750,0.861,0.885,"@ T ",8268
TimeAndSale,AKER,20180402-083542.889-0400,20180402-083542-0400,863:166,D,0.885,250,0.88,0.885,"@ T ",8236
TimeAndSale,AKER,20180402-083803.999-0400,20180402-083803-0400,971:168,D,0.88,3000,0.861,0.885,"@ T ",8236
TimeAndSale,AKER,20180402-083827.112-0400,20180402-083827-0400,100:170,D,0.88,245,0.861,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-084027.275-0400,20180402-084027-0400,262:172,D,0.88,132,0.861,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-084034.297-0400,20180402-084034-0400,284:174,D,0.88,5000,0.861,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-084614.228-0400,20180402-084614-0400,213:176,D,0.88,130,0.861,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-085503.885-0400,20180402-085503-0400,732:178,D,0.87,5000,0.87,0.88,"@ T ",8268
TimeAndSale,AKER,20180402-085552.916-0400,20180402-085552-0400,911:180,P,0.87,1000,0.861,0.88,"@ T ",8268
TimeAndSale,AKER,20180402-085711.772-0400,20180402-085711-0400,769:182,D,0.861,8400,0.861,0.87,"@ T ",8268
TimeAndSale,AKER,20180402-085715.163-0400,20180402-085715-0400,164:184,Z,0.861,200,0.86,0.87,"@FT ",22604
TimeAndSale,AKER,20180402-085715.163-0400,20180402-085715-0400,164:185,Z,0.861,40,0.86,0.87,@FTI,22600
TimeAndSale,AKER,20180402-085746.212-0400,20180402-085746-0400,212:187,K,0.861,900,0.86,0.861,"@FT ",22572
TimeAndSale,AKER,20180402-085900.638-0400,20180402-085900-0400,635:188,D,0.861,5,0.86,0.861,"@ TI",8232
TimeAndSale,AKER,20180402-085956.507-0400,20180402-085956-0400,503:190,D,0.861,460,0.86,0.87,"@ T ",8268
TimeAndSale,AKER,20180402-090022.631-0400,20180402-090022-0400,627:192,D,0.861,2540,0.86,0.87,"@ T ",8268
TimeAndSale,AKER,20180402-090026.088-0400,20180402-090026-0400,86:194,K,0.86,350,0.86,0.87,"@FT ",22604
TimeAndSale,AKER,20180402-090026.088-0400,20180402-090026-0400,87:196,P,0.86,500,0.86,0.87,"@FT ",22604
TimeAndSale,AKER,20180402-090026.088-0400,20180402-090026-0400,87:198,P,0.86,1610,0.86,0.87,"@FT ",22604
TimeAndSale,AKER,20180402-090119.791-0400,20180402-090119-0400,786:200,D,0.87,450,0.86,0.88,"@ T ",8268
TimeAndSale,AKER,20180402-090119.793-0400,20180402-090119-0400,789:202,D,0.872,673,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090121.177-0400,20180402-090121-0400,172:204,D,0.87,200,0.86,0.87,"@ T ",8236
TimeAndSale,AKER,20180402-090121.271-0400,20180402-090121-0400,266:206,D,0.87,250,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090121.366-0400,20180402-090121-0400,359:208,D,0.87,111,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090128.983-0400,20180402-090128-0400,977:209,D,0.87,77,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090129.073-0400,20180402-090129-0400,66:210,D,0.87,30,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090129.284-0400,20180402-090129-0400,281:212,P,0.86,1100,0.86,0.87,"@ T ",8268
TimeAndSale,AKER,20180402-090130.502-0400,20180402-090130-0400,496:214,D,0.87,210,0.86,0.88,"@ T ",8268
TimeAndSale,AKER,20180402-090130.505-0400,20180402-090130-0400,499:216,D,0.88,990,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090130.576-0400,20180402-090130-0400,571:217,D,0.87,32,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090131.472-0400,20180402-090131-0400,468:219,D,0.87,150,0.86,0.87,"@ T ",8236
TimeAndSale,AKER,20180402-090131.566-0400,20180402-090131-0400,560:220,D,0.87,17,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090131.771-0400,20180402-090131-0400,765:221,D,0.87,1,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090132.080-0400,20180402-090132-0400,74:223,D,0.87,300,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090132.175-0400,20180402-090132-0400,171:224,D,0.87,27,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090133.081-0400,20180402-090133-0400,76:226,D,0.87,5000,0.86,0.88,"@ T ",8236
TimeAndSale,AKER,20180402-090133.195-0400,20180402-090133-0400,189:227,D,0.87,38,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090133.880-0400,20180402-090133-0400,876:228,D,0.87,17,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090136.863-0400,20180402-090136-0400,857:229,D,0.87,85,0.86,0.87,"@ TI",8232
TimeAndSale,AKER,20180402-090138.371-0400,20180402-090138-0400,365:231,D,0.869,950,0.86,0.869,"@ T ",8236
TimeAndSale,AKER,20180402-090140.588-0400,20180402-090140-0400,585:233,P,0.86,187,0.86,0.869,"@ T ",8268
TimeAndSale,AKER,20180402-090141.291-0400,20180402-090141-0400,286:235,D,0.865,500,0.86,0.869,"@ T ",8236
TimeAndSale,AKER,20180402-090142.025-0400,20180402-090142-0400,21:237,D,0.865,1000,0.86,0.869,"@ T ",8236
TimeAndSale,AKER,20180402-090142.193-0400,20180402-090142-0400,190:239,P,0.86,2000,0.86,0.869,"@ T ",8268
TimeAndSale,AKER,20180402-090142.571-0400,20180402-090142-0400,568:241,P,0.86,664,0.86,0.869,"@ T ",8268
TimeAndSale,AKER,20180402-090142.579-0400,20180402-090142-0400,576:243,P,0.86,1439,0.86,0.869,"@ T ",8268
TimeAndSale,AKER,20180402-090142.684-0400,20180402-090142-0400,682:245,P,0.8555,425,0.8555,0.859,"@ T ",8268
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:247,P,0.8515,5000,0.85,0.859,"@ T ",8268
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:249,P,0.85,700,0.85,0.859,"@ T ",8268
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:251,P,0.85,2000,0.85,0.859,"@ T ",8268
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:253,P,0.85,500,0.85,0.859,"@ T ",8268
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:254,P,0.85,50,0.85,0.85,"@ TI",8264
TimeAndSale,AKER,20180402-090142.686-0400,20180402-090142-0400,684:256,P,0.85,100,0.85,0.85,"@ T ",8268
TimeAndSale,AKER,20180402-090142.687-0400,20180402-090142-0400,684:258,K,0.85,1000,0.84,0.85,"@FT ",22572
TimeAndSale,AKER,20180402-090142.687-0400,20180402-090142-0400,684:260,K,0.85,1500,0.84,0.85,"@FT ",22572
TimeAndSale,AKER,20180402-090142.687-0400,20180402-090142-0400,684:262,K,0.85,1000,0.84,0.85,"@FT ",22572
TimeAndSale,AKER,20180402-090142.976-0400,20180402-090142-0400,973:264,P,0.84,2066,0.84,0.85,"@ T ",8268
TimeAndSale,AKER,20180402-090143.098-0400,20180402-090143-0400,95:266,P,0.84,361,0.84,0.85,"@ T ",8268
TimeAndSale,AKER,20180402-090143.100-0400,20180402-090143-0400,97:268,P,0.8369,1639,0.8369,0.85,"@ T ",8268
TimeAndSale,AKER,20180402-090143.525-0400,20180402-090143-0400,519:270,D,0.85,1000,0.84,0.859,"@ T ",8236
TimeAndSale,AKER,20180402-090144.254-0400,20180402-090144-0400,248:271,D,0.85,15,0.84,0.85,"@ TI",8232
TimeAndSale,AKER,20180402-090144.260-0400,20180402-090144-0400,256:272,D,0.85,10,0.84,0.85,"@ TI",8232
TimeAndSale,AKER,20180402-090146.742-0400,20180402-090146-0400,736:274,D,0.85,200,0.84,0.85,"@ T ",8236
TimeAndSale,AKER,20180402-090154.948-0400,20180402-090154-0400,941:276,D,0.85,2000,0.84,0.85,"@ T ",8236
TimeAndSale,AKER,20180402-090156.548-0400,20180402-090156-0400,541:277,D,0.85,50,0.84,0.85,"@ TI",8232
您可以使用
之类的内容轻松重新格式化数据Time_and_Sales = pd.read_csv('data/TnS.csv').loc[:, ["EventTime", "Price", "Size"]]
如何使用python3重新取样Time_and_Sales
以获取low
,high
,open
和close
列?请注意,烛台可以选择1
,5
,15
,30
和60
分钟。使用您选择的选项会很舒服。
我想用我的日期制作一个烛台图表,但我不知道该怎么做。到目前为止,我能够建立一个标准图表。
import pandas as pd
from datetime import datetime as dtt
import matplotlib.pyplot as plt
TnS_dataframe = pd.read_csv("data/TnS.csv")
TnS_dataframe['EventTime'] = TnS_dataframe['EventTime'].map(lambda x: datetime.strptime(str(x[:19]), "%Y%m%d-%H%M%S.%f"))
X = TnS_dataframe['EventTime']
Y = TnS_dataframe["Price"]
# plot
plt.plot(X,Y)
# beautify the x-labels
plt.gcf().autofmt_xdate()
plt.show()
答案 0 :(得分:1)
我已成功回答了我自己的问题。这是解决方案:
from pandas_datareader import data as pdr
from datetime import datetime as dtt
import pandas as pd
import plotly.offline as py_offline
import plotly.graph_objs as go
import fix_yahoo_finance as yf
TnS_dataframe = pd.read_csv("data/TnS.csv")
TnS_dataframe['EventTime'] = TnS_dataframe['EventTime'].map(lambda x: datetime.strptime(str(x[:19]), "%Y%m%d-%H%M%S.%f"))
df = TnS_dataframe.loc[:, ["EventTime", "Price"]]
df = df.set_index('EventTime')
test = df.resample('1min').ohlc().bfill()['Price']
yf.pdr_override()
symbol_candle = go.Candlestick(x=test.index,
open=test.open,
high=test.high,
low=test.low,
close=test.close,
increasing=dict(line=dict(color= '#00FF00')),
decreasing=dict(line=dict(color= '#FF0000'))
)
data = [symbol_candle]
layout = go.Layout(
plot_bgcolor='rgb(59,68,75)'
)
fig = go.Figure(data=data, layout=layout)
py_offline.iplot(fig, filename='Candle Stick')