Unable to generate error bars with seaborn Can you please help me add error bars to my graph?

This is the csv:

run,testcase,algorithm,group,avg_weightedcost,std_weight
1,1,QI,0,20007037.36,0
2,1,Q2,0,60000000,3.76E-09
3,1,Q4,0,181801581.2,13353630.74
4,1,Q3,0,585605657.3,54852458.59
6,1,QI,1,10003518.68,0
7,1,Q2,1,292802828.7,2.00E+01
8,1,Q4,1,90900790.6,13353630.74
9,1,Q3,1,292802828.7,27426229.3


This is the code and graph generated:

g = sns.barplot(y="algorithm", x="avg_weightedcost", hue="group", 
capsize=.2, data=df)




This is how I tried to add the error bar:

g = sns.barplot(y="algorithm", x="avg_weightedcost", hue="group", 
xerr="std_weight", capsize=.2, data=df)


This is the error:

ValueError: err must be [ scalar | N, Nx1 or 2xN array-like ]


Modified:

csv file:

run,testcase,algorithm,group,avg_weightedcost,std_weight,avg,err
1,1,QI,0.00,20007037.36,0.00,100.00,5.00
2,1,Q2,0.00,60000000.00,0.00,50.00,20.00
3,1,Q4,0.00,181801581.20,13353630.74,50.00,10.00
4,1,Q3,0.00,585605657.30,54852458.59,20.00,1.00
6,1,QI,1.00,10003518.68,0.00,20.00,20.00
7,1,Q2,1.00,292802828.65,20.00,30.00,10.00
8,1,Q4,1.00,90900790.60,13353630.74,10.00,10.00
9,1,Q3,1.00,292802828.65,27426229.30,50.00,20.00


code:

g = sns.barplot(x=data2['avg_weightedcost'], y=data2['algorithm'], 
hue=data2['group']) 

g.errorbar(x=data2['avg_weightedcost'], y=data2['algorithm'], 
xerr=data2['std_weight'], ecolor='red', linewidth=0, capsize=15) 


Error:

ValueError: could not convert string to float: 'Q3'
I found this question when trying to find a way to add my own precalculated, custom error bars (standard deviations) to a Seaborn barplot with grouped values. I finally managed to find a workaround... The idea is to duplicate the observations drawing from a normal distribution with the desired mean and standard deviation. Then, the built-in "ci" option in sns.barplot does the rest. Not the cleanest solution... but it does the trick (at least for small datasets). An example:

import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

dfBarPlot = pd.read_csv('my_precalculated_values.csv')
#duplicate observations to get good std bars
dfCopy = dfBarPlot.copy()
duplicates = 30 # increase this number to increase precision
for index, row in dfBarPlot.iterrows():
    for times in range(duplicates):
        new_row = row.copy()
        new_row['Y'] = np.random.normal(row['Y'],row['precomputed_std']) 
        dfCopy = dfCopy.append(new_row, ignore_index=True)

# Now Seaborn does the rest
sns.set_style("whitegrid")
fig = sns.barplot(x='X',
                  y='Y',
                  hue='Cases',
                  ci='sd',
                  data=dfCopy)

plt.legend(loc='upper right')
sns.set(rc={'figure.figsize':(8,5)})
plt.show()