import pandas as pd
from pandas import Series,DataFrame
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline
poll_df=pd.read_csv('http://elections.huffingtonpost.com/pollster/2012-general-election-romney-vs-obama.csv')
#poll_df is the data which i have read from a csv file.
sns.factorplot('Affiliation',data=poll_df)
Asked
Active
Viewed 553 times
0

Ben.hardy
- 125
- 1
- 2
- 8
-
If you could provide some example data and more context about the error you are receiving people are more likely to be able to help you. – vielkind Jul 02 '18 at 16:25
-
This code is running smoothly in Python2 but its giving an error in Python3, i think there is some problem in this statement-> sns.factorplot('Affiliation',data=poll_df) – Ben.hardy Jul 02 '18 at 17:59
1 Answers
0
I have difficulty understanding the question. Column Affiliation
has a str
value not numeric
.
if you want to count total number of each str category and have a bar plot try:
import pandas as pd
from pandas import Series,DataFrame
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline
poll_df=pd.read_csv('http://elections.huffingtonpost.com/pollster/2012-general-election-romney-vs-obama.csv')
#poll_df is the data which i have read from a csv file.
sns.countplot('Affiliation',data=poll_df)
alternatively upload the image of what kind of plot you would like to have as a result

H.Bukhari
- 1,951
- 3
- 10
- 15
-
1yeah it worked thanks.But can you explain me why factorplot() was not working when it also does the same work? – Ben.hardy Jul 02 '18 at 18:49
-
1yes since your column contains str values, seaborn facterplot doesn't know what to do with them. So in order to solve this problem we tell Seaborn to use count plot which bassicly take str values and count them to produce bar plots. I hope its helpful. If you have other question please feel free to ask alternatively tick the answer so the question is answered =) – H.Bukhari Jul 02 '18 at 19:00