Попробуйте это:
import os
import numpy as np
from scipy.stats.mstats import winsorize
file_location = input("path to file: ")
dirname = os.path.dirname(file_location)
filename = os.path.basename(file_location)
with open(file_location, 'r') as readfile, \
open(os.path.join(dirname, 'win_' + filename), 'w') as writefile1, \
open(os.path.join(dirname, 'mod_' + filename), 'w') as writefile2:
writefile1.write('adj_mean,adj_std\n')
for idx, line in enumerate(readfile):
print("Reading line# {}...".format(idx))
series = np.array([float(x) for x in line.split(',')])
print("Read {} values...".format(len(series)))
winsorized_series = winsorize(series, limits=[0.10, 0.10])
print("Writing modified series to file...")
writefile2.write(','.join(map(str, winsorized_series)) + '\n')
adj_mean = np.mean(winsorized_series)
adj_std = np.std(winsorized_series)
print("adj mean and std dev...")
writefile1.write("{},{}\n".format(adj_mean, adj_std))