np.genfromtxt missing_values

Viewed 41

I need help in preparing this data with numpy in order to plot it with matplotlib. The Data looks like this:

Label   Power   Cold_junction   Prof100 Prof200 Prof300 Prof400 Prof600 Prof1000    Temp05  Temp10  Temp20  Temp30  Temp50  Temp100
Units   V   deg C   %   %   %   %   %   %   °C  °C  °C  °C  °C  °C
29.09.2020 11:20:00 10,9    25,4    1,8 4,6 3,5 0,2 #-INF   #-INF   22,9    23,1    23,0    23,2    23,0    23,1
29.09.2020 11:30:00 10,9    25,5    1,8 4,5 3,5 0,1 #-INF   #-INF   23,0    23,2    23,1    23,3    23,2    23,3
29.09.2020 11:40:00 10,9    25,7    1,8 4,5 3,4 0,0 #-INF   #-INF   23,1    23,3    23,2    23,3    23,3    23,4
29.09.2020 11:50:00 10,9    25,8    1,7 4,4 3,4 0,0 #-INF   #-INF   23,2    23,4    23,3    

I am having a hard time trying to deal with this #-INF values. So far i tried code like this:

a = np.genfromtxt(r'data.txt', delimiter=(10,10,4,5,4,5,4,4,4), skip_header=2, dtype=str, missing_values={0:"#-INF"},filling_values={0:'#-INF'})
a = np.char.replace(a, ',','.')   # here in Germany we like to replace . with , to make things more complicate
a = np.char.replace(a,'\t',' ')   # because i like the output without '\t' in it

so far my output looks like this:

[['29.09.2020' '11:20:00 10.9 25.4 1.8 4.6 3.5 0.2 ']
['29.09.2020' '11:30:00 10.9 25.5 1.8 4.5 3.5 0.1 ']
['29.09.2020' '11:40:00 10.9 25.7 1.8 4.5 3.4 0.0 ']
['29.09.2020' '11:50:00 10.9 25.8 1.7 4.4 3.4 0.0 ']

and as you can see, all the values behind the '#-INF' are ignored and i don't know what else i can try to stop that... any idea??? i thougt the missing_values would be the right argument to handle my problem, but I am doing something wrong i guess...

1 Answers

np.genfromtxt takes the optional argument comments='#'. You should probably set it to something else, either an empty string, or None, or another character that does not appear in your data.

Related