Reputation: 95
I am trying to do a bar chart using python and seaborn, but I am getting a error:
ValueError: Could not interpret input 'total'.
This is what I am trying to transform in a bar chart:
level_1 1900 2014 2015 2016 2017 2018
total 0.0 154.4 490.9 628.4 715.2 601.5
This is a image of the same dataframe:
Also I want to delete the column 1990
, but when I try to do it by deleting the index, the column 2014
is deleted.
I got this far until now:
valor_ano = sns.barplot(
data= valor_ano,
x= ['2014', '2015', '2016', '2017', '2018'],
y= 'total')
Any suggestions?
Upvotes: 8
Views: 6605
Reputation: 8262
Do something like the following:
import seaborn as sns
import pandas as pd
valor_ano = pd.DataFrame({'level_1':[1900, 2014, 2015, 2016, 2017, 2018],
'total':[0.0, 154.4, 490.9, 628.4,715.2,601.5]})
valor_ano.drop(0, axis=0, inplace=True)
valor_plot = sns.barplot(
data= valor_ano,
x= 'level_1',
y= 'total')
This produces the following plot:
EDIT: If you want to do it without the dataframe and just pass in the raw data you can do it with the following code. You can also just use a variable containing a list instead of hard-coding the list:
valor_graph = sns.barplot(
x= [2014, 2015, 2016, 2017, 2018],
y= [154.4, 490.9, 628.4,715.2,601.5])
Upvotes: 6