forked from ssciwr/Python-best-practices-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplexity1.py
27 lines (23 loc) · 827 Bytes
/
complexity1.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
import numpy as np
import pandas as pd
def read_in(filedir, filename, mydatatype, myheader=False):
if mydatatype == "numpy":
name = "{}{}".format(filedir, filename)
print("Reading from file {} - numpy".format(name))
if myheader:
data = np.loadtxt(name, skiprows=1)
else:
data = np.loadtxt(name, skiprows=0)
data = data.T
elif mydatatype == "pandas":
name = "{}{}".format(filedir, filename)
print("Reading from file {} - pandas".format(name))
data = pd.read_csv(name, sep=r"\s+")
else:
print("Data type not found!")
exit()
return data
if __name__ == "__main__":
read_in("./data/", "efield.t", "numpy", myheader=True)
read_in("./data/", "npop.t", "pandas")
read_in("./data/", "npop.t", "foo")