generate a heatmap from a dataframe with python and seaborn
Question: I'm new to Python and fairly new to seaborn.

I have a pandas dataframe named df which looks like:

    
    
    TIMESTAMP ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F2 ACT_TIME_AERATEUR_1_F3 ACT_TIME_AERATEUR_1_F4 ACT_TIME_AERATEUR_1_F5 ACT_TIME_AERATEUR_1_F6 
    2015-08-01 23:00:00 80 0 0 0 10 0
    2015-08-01 23:20:00 60 0 20 0 10 10
    2015-08-01 23:40:00 80 10 0 0 10 10
    2015-08-01 00:00:00 60 10 20 40 10 10
    
    
    df.info()
    
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 38840 entries, 0 to 38839
    Data columns (total 7 columns):
    TIMESTAMP                 38840 non-null datetime64[ns]
    ACT_TIME_AERATEUR_1_F1    38696 non-null float64
    ACT_TIME_AERATEUR_1_F3    38697 non-null float64
    ACT_TIME_AERATEUR_1_F5    38695 non-null float64
    ACT_TIME_AERATEUR_1_F6    38695 non-null float64
    ACT_TIME_AERATEUR_1_F7    38693 non-null float64
    ACT_TIME_AERATEUR_1_F8    38696 non-null float64
    dtypes: datetime64[ns](1), float64(6)
    memory usage: 2.1 MB
    

I try to do a heatmap using this code :

    
    
    data = sns.load_dataset("df")
    
    # Draw a heatmap with the numeric values in each cell
    sns.heatmap(data, annot=True, fmt="d", linewidths=.5)
    

But it does not work Can you help me pelase to find the error?

Thanks

**Edit** First , I load dataframe from csv file :

    
    
    df1 = pd.read_csv('C:/Users/Demonstrator/Downloads/Listeequipement.csv',delimiter=';', parse_dates=[0], infer_datetime_format = True)
    

Then, I select only rows which date '2015-08-01 23:10:00' and '2015-08-02
00:00:00'

    
    
        import seaborn as sns
        df1['TIMESTAMP']= pd.to_datetime(df1_no_missing['TIMESTAMP'], '%d-%m-%y %H:%M:%S')
        df1['date'] = df_no_missing['TIMESTAMP'].dt.date
        df1['time'] = df_no_missing['TIMESTAMP'].dt.time
        date_debut = pd.to_datetime('2015-08-01 23:10:00')
        date_fin = pd.to_datetime('2015-08-02 00:00:00')
        df1 = df1[(df1['TIMESTAMP'] >= date_debut) & (df1['TIMESTAMP'] < date_fin)]
    
    Then, construct the heatmap :
    sns.heatmap(df1.iloc[:,2:],annot=True, fmt="d", linewidths=.5)
    

I get this error :

>
>     TypeError                                 Traceback (most recent call
> last)
>     <ipython-input-363-a054889ebec3> in <module>()
>           7 df1 = df1[(df1['TIMESTAMP'] >= date_debut) & (df1['TIMESTAMP'] <
> date_fin)]
>           8
>     ----> 9 sns.heatmap(df1.iloc[:,2:],annot=True, fmt="d", linewidths=.5)
>  
>     C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in
>  
>
> heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws,
> linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, ax, xticklabels,
> yticklabels, mask, **kwargs) 483 plotter = _HeatMapper(data, vmin, vmax,
> cmap, center, robust, annot, fmt, 484 annot_kws, cbar, cbar_kws,
> xticklabels, \--> 485 yticklabels, mask) 486 487 # Add the pcolormesh kwargs
> here
>  
>  
>     C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in
>  
>
> **init**(self, data, vmin, vmax, cmap, center, robust, annot, fmt,
> annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask) 165 # Determine
> good default values for the colormapping 166
> self._determine_cmap_params(plot_data, vmin, vmax, \--> 167 cmap, center,
> robust) 168 169 # Sort out the annotations
>  
>  
>     C:\Users\Demonstrator\Anaconda3\lib\site-packages\seaborn\matrix.py in
>  
>
> _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust)
> 202 cmap, center, robust): 203 """Use some heuristics to set good defaults
> for colorbar and range.""" \--> 204 calc_data =
> plot_data.data[~np.isnan(plot_data.data)] 205 if vmin is None: 206 vmin =
> np.percentile(calc_data, 2) if robust else calc_data.min()
>  
>  
>     TypeError: ufunc 'isnan' not supported for the input types, and the
> inputs could not be safely coerced to any supported types
>  
>
> according to the casting rule ''safe''


Answer: Remove the timestamp variables(i.e. first two columns) before passing it to
sns.heatmap, no need for the load dataset as well, just use:

    
    
    sns.heatmap(df.iloc[:,2:],annot=True, fmt="d", linewidths=.5)
    

# EDIT

Ok here is your dataframe, just changed the column names in the interest of
time

    
    
    df
    Out[9]: 
               v1        v2  v3  v4  v5  v6  v7  v8
    0  2015-08-01  23:00:00  80   0   0   0  10   0
    1  2015-08-01  23:20:00  60   0  20   0  10  10
    2  2015-08-01  23:40:00  80  10   0   0  10  10
    3  2015-08-01  00:00:00  60  10  20  40  10  10
    

Now seaborn cannot recognize timestamp variables for the heatmap right, so we
will remove the first two columns and pass the dataframe to seaborn

    
    
    import seaborn as sns
    sns.heatmap(df.iloc[:,2:],annot=True, fmt="d", linewidths=.5)
    

So we get the result as

[![Output from
seaborn](http://i.stack.imgur.com/9BzZK.png)](http://i.stack.imgur.com/9BzZK.png)

If you don't get the result by using this, please edit your question to
include rest of your code. This is not the problem then.

