Pandas an pathlib pt2
In [1]:
# Pathlib edith multiplevalues
In [22]:
import pandas as pd
from pathlib import Path
import shutil
In [2]:
def replace_in_file(file_path, str1, str2):
#read input file
f_in = open(file_path, "rt")
#read file contents to string
data = f_in.read()
#replace all occurrences of the required string
data = data.replace(str1, str2)
#close the input file
f_in.close()
#open the same file in write mode
f_out = open(file_path, "wt")
#overrite the file with the resulting data
f_out.write(data)
#close the file
f_out.close()
In [45]:
files_dmc = Path('./data_simulation/').glob('**/**/*values*.txt')
files_PDCCA = Path('./data_simulation/').glob('**/**/*tables*.txt')
for file in files_PDCCA:
replace_in_file(file, ',', '')
In [50]:
files_PDCCA = Path('./data_out/').glob('**/**/*PDCCA*.txt')
path_01 = list(files_PDCCA)[0]
In [51]:
import pandas as pd
In [53]:
df = pd.read_csv(path_01, sep=' ')
In [54]:
df
Out[54]:
n | rho12 | rho13 | rho14 | rho23 | rho24 | rho34 | |
---|---|---|---|---|---|---|---|
0 | 4 | 0.760061 | 0.684270 | 0.508418 | 0.513245 | 0.508449 | 0.711413 |
1 | 5 | 0.764320 | 0.668200 | 0.486119 | 0.478104 | 0.471227 | 0.688854 |
2 | 7 | 0.781551 | 0.651747 | 0.466251 | 0.443449 | 0.431775 | 0.666639 |
3 | 9 | 0.800796 | 0.645638 | 0.466188 | 0.434620 | 0.420630 | 0.661609 |
4 | 11 | 0.816372 | 0.642035 | 0.473159 | 0.433055 | 0.419693 | 0.662708 |
5 | 13 | 0.828812 | 0.639615 | 0.483356 | 0.434795 | 0.423914 | 0.666626 |
6 | 16 | 0.843128 | 0.637587 | 0.500960 | 0.440563 | 0.435018 | 0.674478 |
7 | 20 | 0.856425 | 0.637008 | 0.523840 | 0.449767 | 0.451689 | 0.684833 |
8 | 23 | 0.863436 | 0.637316 | 0.538322 | 0.455968 | 0.462372 | 0.690960 |
9 | 28 | 0.871284 | 0.638074 | 0.556323 | 0.463410 | 0.474545 | 0.697337 |
10 | 33 | 0.875581 | 0.638884 | 0.568598 | 0.466995 | 0.480815 | 0.700410 |
11 | 38 | 0.877237 | 0.639596 | 0.577043 | 0.467009 | 0.482564 | 0.701830 |
12 | 45 | 0.876467 | 0.640072 | 0.583833 | 0.462281 | 0.478809 | 0.701987 |
13 | 52 | 0.873414 | 0.639615 | 0.586269 | 0.453720 | 0.469767 | 0.700487 |
14 | 60 | 0.868307 | 0.637922 | 0.585748 | 0.441348 | 0.455874 | 0.697579 |
15 | 69 | 0.861494 | 0.635339 | 0.583239 | 0.426509 | 0.438734 | 0.694187 |
16 | 79 | 0.853424 | 0.632594 | 0.579813 | 0.411055 | 0.420112 | 0.691023 |
17 | 91 | 0.843822 | 0.630126 | 0.576024 | 0.395589 | 0.400228 | 0.688057 |
18 | 104 | 0.834231 | 0.628455 | 0.573007 | 0.382984 | 0.382723 | 0.685663 |
19 | 119 | 0.824804 | 0.627456 | 0.571114 | 0.373461 | 0.368305 | 0.683506 |
20 | 135 | 0.817120 | 0.627146 | 0.570672 | 0.368735 | 0.359524 | 0.681523 |
21 | 154 | 0.811207 | 0.627304 | 0.571261 | 0.369216 | 0.356249 | 0.679024 |
22 | 174 | 0.808063 | 0.627567 | 0.571980 | 0.374684 | 0.358535 | 0.675950 |
23 | 198 | 0.806848 | 0.627602 | 0.572156 | 0.384599 | 0.365654 | 0.671797 |
24 | 223 | 0.806645 | 0.627402 | 0.571489 | 0.395762 | 0.374961 | 0.667542 |
25 | 252 | 0.805431 | 0.627078 | 0.570054 | 0.406522 | 0.384524 | 0.663173 |
26 | 285 | 0.801432 | 0.625991 | 0.567398 | 0.413280 | 0.390904 | 0.658420 |
27 | 321 | 0.795125 | 0.622777 | 0.562381 | 0.414375 | 0.392598 | 0.652446 |
28 | 362 | 0.788254 | 0.616244 | 0.553995 | 0.410533 | 0.391414 | 0.644081 |
29 | 407 | 0.782478 | 0.606658 | 0.542966 | 0.402544 | 0.389501 | 0.633788 |
30 | 457 | 0.778289 | 0.596822 | 0.532642 | 0.392815 | 0.389975 | 0.623522 |
31 | 513 | 0.775795 | 0.589098 | 0.524813 | 0.383588 | 0.393465 | 0.614296 |
32 | 575 | 0.775403 | 0.583926 | 0.518941 | 0.376264 | 0.398467 | 0.607003 |
33 | 645 | 0.776380 | 0.579773 | 0.512178 | 0.371013 | 0.402677 | 0.602293 |
34 | 723 | 0.778667 | 0.575429 | 0.503394 | 0.367814 | 0.405080 | 0.600395 |
35 | 809 | 0.782200 | 0.570337 | 0.493671 | 0.366048 | 0.406000 | 0.600701 |
36 | 905 | 0.786615 | 0.565534 | 0.485843 | 0.367141 | 0.408390 | 0.604788 |
37 | 1011 | 0.791235 | 0.563392 | 0.483736 | 0.373832 | 0.416242 | 0.613622 |
38 | 1130 | 0.795885 | 0.565740 | 0.489388 | 0.386496 | 0.431217 | 0.626992 |
39 | 1261 | 0.798482 | 0.573270 | 0.503071 | 0.403482 | 0.452505 | 0.643278 |
40 | 1407 | 0.799359 | 0.583587 | 0.520701 | 0.421681 | 0.476888 | 0.659848 |
41 | 1570 | 0.798991 | 0.591055 | 0.535089 | 0.436085 | 0.499760 | 0.674025 |
42 | 1750 | 0.798090 | 0.590516 | 0.542369 | 0.441946 | 0.517148 | 0.684802 |
43 | 1950 | 0.797723 | 0.580736 | 0.542156 | 0.438549 | 0.526096 | 0.691883 |
In [ ]: