I do want to read some .csv files and print the minimum and maximum value of the 5th column. I also want to print in which file I can find the max or min.
My code is right now:
import pandas, glob
import numpy as np
path = "/home/path/to/log/"
fn = glob.glob(path + "*.csv")
list_of_dfs = [pandas.read_csv(filename, header=None) for filename in fn]
k = len(list_of_dfs)
b = np.zeros((k, 1))
cnt = 0
for i in list_of_dfs:
b[cnt,0] = np.min(i[4])
cnt = cnt + 1
print(np.min(b[:,0]))
print(np.argmin(b[:,0]))
My .csv Files are named like:
0.csv, 1.csv ... 10.csv ...2463.csv
After seeing that my argmin doesn't show the correct file I realised that fn isn't sorted. I found this Sort filenames in directory in ascending order, where the solution was:
fn.sort(key=lambda f: int(filter(str.isdigit, f)))
But with this line I get the following error:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'filter'
Any Suggestions?