Skip to content

Instantly share code, notes, and snippets.

@whosaysni
Last active November 6, 2016 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whosaysni/12b69457b6c2289e1a71a1e702b4526e to your computer and use it in GitHub Desktop.
Save whosaysni/12b69457b6c2289e1a71a1e702b4526e to your computer and use it in GitHub Desktop.
・・・宿題?
import numpy as np
file_paths = glob('/b/*.csv') # /b/*.csv ファイル
for offset in [1, 11]:
col3_avgs = []
col2_avgs = []
for i in range(10):
file_path = '/b/a{}.csv'.format(offset+i)
data = np.load.text(file_path, comments='#', delimiter=',', skiprows=1)
avg_col3 = np.mean(data[:, 2])
avg_col2 = np.mean(data[500001:750001, 1])
print('Average of col #3 in {} is {}'.format(file_path, avg_col3))
print('Average of col #2, row (500001, 750001) in {} is {}'.format(file_path, avg_col2))
col3_avgs.append(avg_col3)
col2_avgs.append(avg_col2)
col3_avg_avg = np.mean(np.array(col3_avgs))
col2_avg_avg = np.mean(np.array(col2_avgs))
print('Col3 average over files a{}~ is {}'.format(offset, col3_avg_avg))
print('Col2 average over files a{}~ is {}'.format(offset, col2_avg_avg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment