'Error creating heatmap from data frame with seaborn

I am trying to create a heat map from a data frame. Each column I am using is made up of numpy.float64.

def create_visual(x, y , z,aggfunc = 'mean'):
    bip_2 = bip[[x,y,z]]
    bip_2 = bip_2.pivot_table(index=x, columns=y, values=z, aggfunc=aggfunc)
    ax = sns.heatmap(bip_2)

Each column is a list of numpy.float64. The error I am recieving is:

TypeError: float() argument must be a string or a number, not 'NAType'

The data frame is:

hc_x1 hc_y1 delta_run_exp
3171 152.0 155.0 -0.082
3340 145.0 148.0 -0.134
1632 155.0 174.0 -0.309
1776 20.0 106.0 0.422
1892 168.0 61.0 -0.207
... ... ... ...
3782 136.0 150.0 -0.349
1759 155.0 172.0 -0.390
2681 99.0 176.0 -0.566
3241 65.0 122.0 0.700
3408 87.0 110.0 0.327

Thank you.



Solution 1:[1]

NAType in Pandas typically represents missing data. Have you checked to see if there is any missing data in your DataFrame?

You can do this for the whole DataFrame with df.isnull().values.any().

For example:

frame = pd.DataFrame({'col1' : [1, 2, 3, None], 'col2' : ['a', None, 'b', 'c']})
check = frame.isnull().values.any()
print(check)

If you find that you have NaN values, you can be more specific in that query and find the columns and rows. Pandas also lets you replace NaN values with df.fillna() or drop them with df.dropna().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gray-lab