With Python or Pandas, extract only the strings from a txt or dat-file -
i have .dat-file following shape , being few hundred lines long:
aloh 200 6000 1000 7.882068110e+05 -2.263671626e+03 7.823954880e+00 1.821171456e-04 -8.263729320e-08 1.265414876e-11 -6.875972530e-16 -1.039808093e+04 -2.209032458e+01 5.876493180e+04 -9.449422690e+02 7.820599180e+00 5.858888470e-04 -4.083666810e-06 4.587229340e-09 -1.563936726e-12 -1.993283011e+04 -2.065043885e+01 al2o 200 6000 1000 -1.171074351e+05 -1.783009166e+02 7.633215360e+00 -5.335931770e-05 1.180702791e-08 -1.355444579e-12 6.287323890e-17 -1.947580149e+04 -1.415764167e+01 7.776530700e+03 -1.294235361e+02 4.912509520e+00 8.604223450e-03 -1.217703648e-05 8.314634870e-09 -2.237722201e-12 -1.886512879e+04 -2.806368311e-02 al2o3 200 6000 1000 -2.777784969e+05 -4.917465930e+02 1.386703888e+01 -1.469381940e-04 3.250406490e-08 -3.730867350e-12 1.730444284e-16 -6.790757850e+04 -4.375559873e+01 -7.443374320e+03 8.829004210e+01 5.264662640e+00 2.507678848e-02 -3.434541650e-05 2.302516980e-08 -6.122529280e-12 -6.872685950e+04 2.202324298e+00 i want extract chemical names (so strings) it, preferably list [aloh, al2o, al2o3, ...]. tried pandas, due strange format of columns file not being read. haven't found on internet other solution short , simple, though should have nice pythonic solution.
has 1 solution how extract strings?
suggested solution:
chemicals = [] open('bla_file.dat') file: line in file: line = line.split() item in line: try: float(item) except valueerror: chemicals.append(item) please post solutions might simpler or shorter!
start parsing either select stings want or deselect unwanted based on characters or data type.
example deselecting based on characters in unwanted strings:
nstr = ['.','+','-'] line in lines: str = line.split(' ') str in line: if str.findall(nstr): continue else print str
Comments
Post a Comment