标题: [问题求助] 【己解决】求Python代码读取指定行对应的数字 [打印本页]
作者: keshun 时间: 2020-6-30 23:08 标题: 【己解决】求Python代码读取指定行对应的数字
本帖最后由 keshun 于 2020-7-1 20:55 编辑
- open high low close volume MA_10 MA_20
- 1 9717.5 9834.2 9680.9 9759.2 69250.06168435 NaN NaN
- 2 9759.3 9999 9500 9522.6 109463.51154308 NaN NaN
- 3 9522.6 9566.3 9056.2 9418.2 82493.28314455 NaN NaN
- 4 9418.2 9488.5 9301.8 9436.4 60685.84440805 NaN NaN
- 5 9436 9494.8 9309.1 9418.3 56135.01126463 NaN NaN
- 6 9418.3 9429.5 8910.4 9296.2 64881.99571136 NaN NaN
- 7 9296.2 9592.2 9281.3 9452.7 65942.38137758 NaN NaN
- 8 9452.8 9566 9369.2 9399.8 69108.10358129 NaN NaN
- 9 9399.8 9486 9231 9385.8 69546.26314103 NaN NaN
- 10 9386.5 9438 9240 9383.5 78708.89882824 9447.27 NaN
- 11 9383.5 9386.4 9172.1 9258.9 87117.47978114 9397.24 NaN
- 12 9258.9 9420 9240.7 9372.5 85171.62890608 9382.23 NaN
- 13 9373.1 9506.8 9276 9491.1 73702.43377556 9389.52 NaN
- 14 9491.2 9786.1 9474 9693.2 87451.29230179 9415.20 NaN
- 15 9693.2 9695.5 9205.1 9250.0 67853.28288908 9398.37 NaN
- 16 9249.6 9340.9 9007.4 9238.8 69483.43733731 9392.63 NaN
- 17 9238.9 9340.1 9046 9150.2 66812.37880788 9362.38 NaN
- 18 9150.9 9215.9 9091.6 9131.9 35669.09547634 9335.59 NaN
- 19 9131.9 9176.9 8818 9158.2 36168.75263589 9312.83 NaN
- 20 9158.9 9190 9028 9123.8 30741.21146648 9286.86 9367.065
- 21 9123.9 9235.5 9063.7 9176.7 43827.29149175 9278.64 9337.940
复制代码
求Python代码读取第21行对应的数字MA_10:9278.64 MA_20:9337.940
作者: Blakelee 时间: 2020-7-1 09:15
是txt文件么?
作者: Blakelee 时间: 2020-7-1 11:17
z = input("please input row number:")
dataList=[]
with open("b.txt", 'r', encoding='UTF-8') as f: # open your file
readList = f.read().splitlines()
for data in readList:
if data.startswith(z):
rowData=["",""]
dataList.append(rowData)
rowData[0]=data.split()[-2].strip()
rowData[1]=data.split()[-1].strip()
for r in dataList:
print(r)
作者: ivor 时间: 2020-7-1 17:19
就题解题- import pandas
- df = pandas.read_csv("num", sep='\s+')
- df.loc[df.index== 21]
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |