Pandas module is ideal for processing tabular (2D) data.
Example:
Let's create a test file of a similar structure, as a data, take a quote from Apple starting in 2001 (4,490 lines)
import pandas as pd # pip install pandas from pandas_datareader.data import DataReader # pip install pandas-datareader df = DataReader('AAPL', 'yahoo', '2001-01-01', '2018-11-06').reset_index() df.to_csv('c:/temp/data.csv', index=False)
Several lines from the file:
Date,High,Low,Open,Close,Volume,Adj Close 2001-01-02,1.0892857313156128,1.0401785373687744,1.0625,1.0625,113078000.0,0.713999330997467 2001-01-03,1.1919642686843872,1.03125,1.0357142686843872,1.1696428060531616,204268400.0,0.7859991192817688 2001-01-04,1.3214285373687744,1.2008928060531616,1.2957571744918823,1.21875,184849000.0,0.818999171257019 2001-01-05,1.2410714626312256,1.1473214626312256,1.2098214626312256,1.1696428060531616,103089000.0,0.7859991192817688 2001-01-08,1.2131643295288086,1.1383928060531616,1.2098214626312256,1.1830357313156128,93424800.0,0.7949992418289185
Decision:
import pandas as pd df = pd.read_csv(r'c:/temp/data.csv')
Search for rows with the lowest and highest values ββin the Adj Close field:
In [27]: print(df.nsmallest(1, ['Adj Close'])) Date High Low Open Close Volume Adj Close 573 2003-04-17 0.946429 0.908571 0.942857 0.937143 154064400.0 0.629759 In [28]: print(df.nlargest(1, ['Adj Close'])) Date High Low Open Close Volume Adj Close 4466 2018-10-03 233.470001 229.779999 230.050003 232.070007 28654800.0 232.070007
TOP 5 values:
In [29]: print(df.nlargest(5, ['Adj Close'])) Date High Low Open Close Volume Adj Close 4466 2018-10-03 233.470001 229.779999 230.050003 232.070007 28654800.0 232.070007 4465 2018-10-02 230.000000 226.630005 227.250000 229.279999 24788200.0 229.279999 4445 2018-09-04 229.179993 226.630005 228.410004 228.360001 27390100.0 228.360001 4467 2018-10-04 232.350006 226.729996 230.779999 227.990005 32042000.0 227.990005 4444 2018-08-31 228.869995 226.000000 226.509995 227.630005 43340100.0 227.630005
220.32,220.32,203.03,203.95,51774,0these prices? - gil9rednew_line1[3:], will return['220.32', '220.32', '203.03', '203.95', '51774', '0']- gil9rednew_line1[3:-1], since 0 will always be the minimum of the sequence. - SinCap