Example csv:
Date,1,2,3,4,A,B 2010-01-04,213.429998,214.499996,212.38000099999996,214.009998,123432400,27.727039 2010-01-05,214.599998,215.589994,213.249994,214.379993,150476200,27.774976000000002 2010-01-06,214.379993,215.23,210.750004,210.969995,138040000,27.333178000000004 2010-01-07,211.75,212.000006,209.050005,210.58,119282800,27.28265 2010-01-08,210.299994,212.000006,209.06000500000002,211.98000499999998,111902700,27.464034 It is required to sort the resulting values only on Mondays, and then the values of Mondays to sort from larger to smaller. For example, there are dates in csv 2010.01.01.-31 - Mondays there are only 4, 11, 18, 25 number. It is necessary to leave only the rows with these dates and the specified column 'total'
import os import glob import pandas as pd import matplotlib matplotlib.style.use('ggplot') file_mask = r'C:/Users/II/Downloads/*.csv' files = glob.glob(file_mask) for f in files: df = pd.read_csv(f, index_col='Date', encoding='latin1') df['total'] = df['1'] - df['2'] # теперь нужно отсортировать значения на основе дат по понедельникам. df = df.sort('total') # сортировка данных в столбце от большего к меньшему. new_fn = '{0[0]}_total{0[1]}'.format(os.path.splitext(f)) df.to_csv(new_fn) 
нужно отсортировать значения на основе дат по понедельникам. Can you give an example of your data (or a piece of code to create it) and the expected result? - MaxUзначения понедельников отсортировать от большего к меньшему- sort by which field? Bytotal? - MaxUстолбец "1" - соответствует "Open", "2" - "High"? - MaxU