Imago
Imago

Reputation: 501

How to prevent seaborn from converting string to floats?

I have currently strings in the form "0.123" saved in a pandas Dataframe in the "A" and integers in the column B. Now I try to create a barplot:

ax = sns.barplot(x='A', y='Y',
                 data=df)

However, the numbers in A are interpreted as floats. As some of the floats cannot be represented properly due to floating point precision. E.g.

E.g. 0.650 becomes 0.649999999999. How can I prevent seaborn from doing something like that? Visualizing data becomes pretty meaningless like this.

Upvotes: 0

Views: 257

Answers (1)

Maciek Woźniak
Maciek Woźniak

Reputation: 455

Check your data everything should work fine!

import pandas as pd 
import seaborn as sns
df = pd.DataFrame(data=[[1,2],[3,4]],columns=['A','Y'])
ax = sns.barplot(x='A', y='Y',
                 data=df)

generated plot

Upvotes: 1

Related Questions