-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestavg.py
45 lines (39 loc) · 1.54 KB
/
testavg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pandas as pd
import numpy as np
import glob
import os
dir = "/Users/luke/Desktop/Python/GitClone/PROJECT-Automate-Research-Process/testfolder"
files = os.listdir(dir)
files_of_interests = {}
for filename in files:
if filename[-4:] == '.csv':
key = filename[:-5]
files_of_interests.setdefault(key, [])
files_of_interests[key].append(filename)
print(filename)
#print(files_of_interests)
#print(os.path.join(dir, filename))
#wavelength_r = np.arange(1100, 1500, 10)
# wl_df = pd.DataFrame.from_records([wavelength_r]).T
# print(wl_df)
# for key in files_of_interests:
# #stack_df = pd.DataFrame.from_records([wavelength_r]).T
# #stack_df = stack_df.rename(columns = {'1', 'Wavelength'})
# stack_df = pd.DataFrame()
# print(stack_df)
# for filename in files_of_interests[key]:
# stack_df = stack_df.append(pd.read_csv(os.path.join(dir, filename)))
# #stack_df.set_index('Unnamed:0', inplace = True)
# print(stack_df)
for key in files_of_interests:
list = []
for filename in files_of_interests[key]:
list.append(pd.read_csv(os.path.join(dir,filename), index_col = 0))
df = pd.concat(list, axis = 1)
df = df.drop(['Wavelength.1'], axis = 1)
df = df.groupby(['Wavelength']).mean().reset_index()
#df = df.groupby(by = df.columns, axis = 1).mean()
#df = df.apply(pd.to_numeric, errors = 'ignore')
#df = df.div(len(files_of_interests[key]))
print(df)
#df.to_csv(os.path.join(dir + '/', f"{filename[:-5]}_master.csv"))