-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylib.py
117 lines (73 loc) · 2.63 KB
/
mylib.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# import csv
import pandas as pd
# import numpy as np
r = [['closed',100],['periodic',100],['closed',400],['peridoic',400]]
for k,j in r:
print(k,j)
# boundary = 'closed'
# w=100
# h=100
# benchmark = pd.read_csv(f'{boundary}_{str(w)}x{str(h)}/benchmark.csv')
# partit = pd.read_csv(f'{boundary}_{str(w)}x{str(h)}/partition.csv')
# ideal = pd.read_csv(f'{boundary}_{str(w)}x{str(h)}/ideal_gas.csv')
# print(benchmark)
# print("\n")
# print(partit)
# print("\n")
# print(ideal)
# # ---- ---- DELETING ROWS ---- ----
# df = pd.read_csv('ideal_gas.csv')
# df.drop("Unnamed: 0",axis=1,inplace=True)
# df.to_csv('ideal_gas.csv',index=False)
# ---- ---- Adding ROWS ---- ----
# newcol = pd.DataFrame({
# 'rule_number':[['stuff']],
# 'E':[['heyo']]
# })
# newcol.to_csv('partition.csv',mode='a',index=False)
# s = 0
# for i in range(5):
# for j in range(5):
# if(j==2):
# break
# else:
# print(i,j)
# new_cols = pd.DataFrame({
# 'rule_name':['Null Name'],
# 'Class':['Null Class']
# })
# print(new_cols)
# new_cols.to_csv('classes.csv',index=False,header=False)
# data = {'rule': ["Null rule"],
# 'Class': ["Null Class"]}
# df = pd.DataFrame(data)
# # Save the DataFrame to a CSV file without row index
# df.to_csv('classes.csv', index=False)
# # ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# # ADDING NEW ROWS TO CSV
# somedata = [15,[2,2,4,4,42,2,51],6,1,2,4,3]
# row_number = 1
# existing_rows = []
# with open(path, 'r') as file:
# reader = csv.reader(file)
# existing_rows = list(reader)
# # Insert the new row at the specified row number
# existing_rows.insert(row_number, somedata)
# # Write the updated rows back to the CSV file
# with open(path, 'w', newline='') as file:
# writer = csv.writer(file)
# writer.writerows(existing_rows)
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# # READING VALUES FROM CSV FILE.
# energy = pd.read_csv('benchmark.csv')
# r = energy[energy['rule_number'] == 15]
# v = r['E']
# val = v.values[0]
# val = eval(val)
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# # ADD A NEW COLUMN
# energy = pd.read_csv('partition.csv',header=None)
# empty_col = pd.DataFrame(['']*len(energy))
# energy.insert(7, 'Z', empty_col)
# Save to csv
# energy.to_csv('partition.csv', index = False, header = False)