I take this dataset and preformat the columns numerically to represent currency and thousands commas. Printing the dataset shows the formatted numbers. But when I use the data in a scatter plot and set the hover data, the formatting is stripped. First the code:
<code> scatter_df["cost"] = "$" + scatter_df["cost"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LRC"] = "$" + scatter_df["LRC"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LR"] = scatter_df["LR"].apply(lambda x: "{:,}".format(x))
print(scatter_df)
fig = px.scatter(
scatter_df,
x="LR",
y="LRC",
color="country",
title="Reach to Cost",
hover_data={
"cost": True,
},
)
</code>
<code> scatter_df["cost"] = "$" + scatter_df["cost"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LRC"] = "$" + scatter_df["LRC"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LR"] = scatter_df["LR"].apply(lambda x: "{:,}".format(x))
print(scatter_df)
fig = px.scatter(
scatter_df,
x="LR",
y="LRC",
color="country",
title="Reach to Cost",
hover_data={
"cost": True,
},
)
</code>
scatter_df["cost"] = "$" + scatter_df["cost"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LRC"] = "$" + scatter_df["LRC"].apply(lambda x: "{:,.2f}".format(x))
scatter_df["LR"] = scatter_df["LR"].apply(lambda x: "{:,}".format(x))
print(scatter_df)
fig = px.scatter(
scatter_df,
x="LR",
y="LRC",
color="country",
title="Reach to Cost",
hover_data={
"cost": True,
},
)
And here is the data:
country | cost | LRC | LR. |
---|---|---|---|
Afghanistan | $2,665.70 | $0.23 | 11,746 |
Azerbaijan | $6,172.40 | $4.31 | 1,433 |
Brazil. | $7,084.11 | $0.44 | 16,083 |
Georgia | $4,311.19 | $1.14 | 3,795 |
And here is a photo of the hover:
The LR lost its comma, and the LRC lost the $. Not even the AI’s have been able to answer why or how to fix.