티스토리 뷰
input_comma폴더 파일을 다음과 같이 6개가 존재한다.
파일은 다음과 같다.
x_coordinate, y_coordinate,
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
46
47
48
|
import pandas as pd
import os
path_dir = './input_comma/' #폴더명
file_list = os.listdir(path_dir)
print(file_list)
new_excel = pd.DataFrame(
columns=['file_name','average1', 'average2', 'average3'])
for i in range(0, len(file_list)):
sum0 = 0
sum1 = 0
sum2 = 0
file_name = file_list[i]
print("file_name : " , file_list[i])
read_excel = pd.read_csv(path_dir + file_name)
#print(read_excel)
for j in range(0, read_excel.shape[0]):
# print(list_split)
x_coordinate = read_excel.iloc[j, 1]
y_coordinate = read_excel.iloc[j, 2]
z_coordinate = read_excel.iloc[j, 3]
velocity_magnitude = float( read_excel.iloc[j, 4])
ap_moment_2 = float( read_excel.iloc[j, 5])
ap_moment_3 = float( read_excel.iloc[j, 6])
ap_moment_4 = float( read_excel.iloc[j, 7])
sum0 = ap_moment_2 + sum0
sum1 = ap_moment_3 + sum1
sum2 = ap_moment_4 + sum2
average1 = sum0 / (read_excel.shape[0])
average2 = sum1 / (read_excel.shape[0])
average3 = sum2 / (read_excel.shape[0])
new_excel.loc[i] = [file_name, average1, average2, average3]
new_file_name = "Result_comma.csv"
new_excel.to_csv(new_file_name, mode='w')
|
cs |
'Programming > python' 카테고리의 다른 글
numpy.random.RandomState (0) | 2019.09.10 |
---|---|
pandas 데이터 전처리하는 방법 (0) | 2019.09.09 |
python - BeautifulSoup, re (0) | 2019.09.06 |
python - matplot & seaborn (0) | 2019.09.05 |
python - PIL (0) | 2019.09.05 |
댓글