title: Show more time details in a correlation pairplot graph based on time series data
body: <p>I have been measuring the air quality in my flat since a while, after being noticing an exposure to second-hand smoke coming from the downstair flat (...). I am using a PMS5003 sensor mounted on an enviro+ attached to a Raspberry. Until recently, I had only measured small particles, but I managed to add gas measurements recently. I am interested to see if there is a <strong>correlation between the different values.</strong> My hypothesis is that CO and nh3 concentration in the air will be high (so the value read by the sensor low, cf. <a href="https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-enviro-plus" rel="nofollow noreferrer">Enviro+ explanation</a>), when there is smoke entering the flat, which will collerate with high PM 2.5 values coming from combustion.</p>
  <p>The data comes in a csv files like this:
  <code> pm2_5_combustion;2021-01-09 20:14:00;166.24242424242425</code></p>
  <p>which is then parsed to this:</p>
  <pre><code>air_quality = pd.read_csv(&quot;processed/pms5003_gas.csv&quot;, sep=&quot;;&quot;)
  air_quality.info()
  air_quality[&quot;unit&quot;].unique()
  
  &lt;class 'pandas.core.frame.DataFrame'&gt; RangeIndex: 92208 entries, 0 to 92207 Data columns (total 3 columns):
  #   Column   Non-Null Count Dtype  
   ---  ------   --------------  -----
  0   unit     92208 non-null  object
  1   time     92208 non-null  object
  2   reading  86445 non-null  float64
  dtypes: float64(1), object(2)
  memory usage: 2.1+ MB
  
  array(['adc', 'gt_0_3um', 'gt_0_5um', 'gt_10um', 'gt_1um', 'gt_2_5um',
          'gt_5um', 'nh3', 'oxidising', 'pm10_atmos', 'pm10_dust',
          'pm1_atmos', 'pm1_ultrafine', 'pm2_5_atmos', 'pm2_5_combustion',
          'reducing'], dtype=object)
  </code></pre>
  <p>Hereunder are some of the codes I have been trying to use to achieve the goal.</p>
  <pre><code>import datetime as dt
  import matplotlib.pyplot as plt
  import numpy as np
  import seaborn as sns
  
  air_quality = pd.read_csv(&quot;processed/pms5003_gas.csv&quot;, sep=&quot;;&quot;)
  air_quality.info()
  air_quality[&quot;unit&quot;].unique()
  
  air_quality[&quot;time&quot;] = pd.to_datetime(air_quality[&quot;time&quot;]) #did not work
  
  air_quality = air_quality.rename(columns={&quot;time&quot;: &quot;datetime&quot;}) #renaming the column did not change much
  
  # C. picking the values I would like to see the correlation between the following values
  datetime = air_quality[air_quality[&quot;datetime&quot;] == &quot;datetime&quot;]
  pm2_5 = air_quality[air_quality[&quot;unit&quot;] == &quot;pm2_5_combustion&quot;]
  pm10 = air_quality[air_quality[&quot;unit&quot;] == &quot;pm10_dust&quot;]
  ox = air_quality[air_quality[&quot;unit&quot;] == &quot;oxidising&quot;]
  red = air_quality[air_quality[&quot;unit&quot;] == &quot;reducing&quot;]
  nh3 = air_quality[air_quality[&quot;unit&quot;] == &quot;nh3&quot;]
  
  # D. Trying with the below, did not work:
  air_quality[&quot;weekday&quot;] = air_quality[&quot;time&quot;].dt.weekday
  air_quality[&quot;date&quot;] = air_quality[&quot;time&quot;].dt.date
  air_quality[&quot;hm&quot;] = air_quality[&quot;time&quot;].dt.hour
  air_quality[&quot;hour&quot;] = air_quality[&quot;time&quot;].dt.hour
  
  air_quality[&quot;datetime&quot;] = pd.to_datetime(air_quality[&quot;datetime&quot;])
  air_quality[&quot;date&quot;] = air_quality[&quot;datetime&quot;].dt.date
  air_quality[&quot;hour&quot;] = air_quality[&quot;datetime&quot;].dt.hour
  air_quality[&quot;min&quot;] = air_quality[&quot;datetime&quot;].dt.minute
  
  # A. Making a pivot and then picking the columns I would like to see the correlation
  df = air_quality.pivot(index=&quot;datetime&quot;, columns=&quot;unit&quot;, values=&quot;reading&quot;)            
  df2 = df[[&quot;pm2_5_combustion&quot;, &quot;pm10_dust&quot;, &quot;reducing&quot;, &quot;nh3&quot;, &quot;oxidising&quot;]]
  
  # B. I also tried to concatenate the columns like that (did not work either):
  frames = [datetime, pm2_5, pm10, ox, red, nh3]
  result = pd.concat(frames)
  
  # I can calculate the correlation without problem
  df2.corr(method='pearson')
  
  # I can also create some correlation graphs with sns.pairplot
  sns.pairplot(
      df2,
      #hue=&quot;hour&quot;,
      #plot_kws=dict(marker=&quot;+&quot;, linewidth=1),
      #diag_kws=dict(fill=False)
      )
  
  </code></pre>
  <p>What I am struggling with, is to get the &quot;hue&quot; parameter to work. With C and D above, I get this table:
  <a href="https://i.stack.imgur.com/MYHRN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MYHRN.png" alt="Desired table to have in pivot with date, hour, min" /></a></p>
  <p>It is ok, but somewhat I cannot get the date, hour and min values, after I use the .pivot function (?), which is what I believe prevents me to getting to this:
  <a href="https://i.stack.imgur.com/r6vqx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r6vqx.png" alt="Desired outcome with a breakdown of the different point here by species, but in my case, by hour of the day or other type of time" /></a>
  <a href="https://seaborn.pydata.org/generated/seaborn.pairplot.html" rel="nofollow noreferrer">seaborn pairplot explanation</a>
  I spent the whole yesterday trying things out and reading the pandas documentation, but I am short in idea as to what I should try next, hence my question here as an alternative to tossing my laptop on my smoking neighbour's face.</p>