Data Extraction and Separation python

K line data extraction

The original dataset based format, as required to generate a new table:
1, each of the first minute of the close data, the last, maximum and minimum values,
2, growth (last vol per minute per minute vol Data data of the first data subtraction)
3, summary information to generate a new table
(field: [ 'Time', 'Open', 'Close', 'High', 'Low', 'Vol'])
Import AS PD PANDAS
Time Import
Start the time.time = ()
DF = pd.read_csv ( 'the data.csv')
DF = df.drop ( 'id', Axis =. 1) remove # id column
df1 = pd.DataFrame (columns = [ ' time ',' open ',' close ',' high ',' low ',' vol ']) # Create target table

for i in df.groupby ( 'time' ): # time packet
new_df = pd.DataFrame (columns = [ ' time', 'open', 'close', 'high', 'low', 'vol']) # Create an empty table for temporary data forwarding request
new_df.time = i [1] .time [ 0: 1] # each time a new table take time
new_df.open = i [1] .close [ 0: 1] # take a close each first data for a new data table open
new_df.close = i [1] [ ' close']. iloc [-1] # take a last close each set of data tables for the new data close
new_df.high = i [1] [ 'close' ]. max () # close each take the maximum value for the new table data hige data
new_df.low = i [1] [ ' close']. min () # fetch data each minimum close The new low value table data
new_df.vol = i [1] [ ' vol'] iloc [-1] -.. i [1] [ 'vol'] iloc [0] # data of each block with the maximum minus vol vol minimum value for the new table data
df1 = pd.concat ([new_df, df1 ], axis = 0) # longitudinal merged table data to the destination

df2 = df1.sort_values ( 'time') # column values sorted by time
df2.reset_index (inplace = True, drop = True) # reset line index
print (df2) # print target data table
stop = time.time () See # Processed
print ( 'total time: {} seconds' .format (stop-start))

Guess you like

Origin blog.51cto.com/14471175/2433685