I have some data that looks like this:
#date time temp press rh
09/10/2011 07:50 11.4 798.1 14.1
09/10/2011 08:00 11.9 798.3 13.6
...
09/10/2011 11:30 FALSE FALSE FALSE
09/10/2011 11:40 25.4 798.3 11.2
09/10/2011 11:50 23.2 799.1 11.2
.....
I want to do a contour plot of "temp" with the "time" in the x-axis and "date" in the y-axis.
I tried using Pandas to handle the dates and the NaN values better.
data=np.genfromtxt("dataFile.txt", comments="#", dtype='str')
header_names=['date', 'time', 'temp', 'press', 'rh']
df = pd.DataFrame(data, dtype=None, columns=header_names)
df['date']=pd.to_datetime(df['date'], format='%d/%m/%Y').dt.date
df.time=pd.to_datetime(df.time, format='%H:%M').dt.time
df.temp = pd.to_numeric(df.temp, errors='coerse')
....
dfMesh=df.pivot('date', 'time', 'temp')
X=dfMesh.columns.values
Y=dfMesh.index.values
Z=dfMesh.values
x,y=np.meshgrid(X, Y)
plt.contourf(x, y, Z)
But I get the following error:
Traceback (most recent call last): File "./contourPlot_pandas.py", line 33, in x,y=np.meshgrid(X, Y) File "/Users/marybau/anaconda/lib/python3.6/site-packages/numpy/lib/function_base.py", line 4533, in meshgrid return [x * mult_fact for x in output] File "/Users/marybau/anaconda/lib/python3.6/site-packages/numpy/lib/function_base.py", line 4533, in return [x * mult_fact for x in output] TypeError: unsupported operand type(s) for *: 'datetime.time' and 'int
'
I have also tried different other ways to do it without using pandas, but I end up with similar problems due to the date-time format or the NaN. Any suggestions? Thanks!