'Python how ?comparing two columns data into one dataframe
so i have grouping data from this column
and then i want to comparing 2 type of the country is 'US' & 'GB into one dataframe so i can make vissualization from this data
so i create new variable for comparing beetwen US and GB
df_compare = df_new.loc[
(df_new['country'].isin(["US", "GB"]))][['ID','name','main_category','usd_goal_real','usd_pledged_real','backers','country','state']]
but i want to make visualization that comparing US and GB, when i try to put my code to make vissualization with pandas the count of "main_category" get combine from country 'US' and 'GB'
and this is my code that i used
fig = plt.figure(figsize=(20, 15))
barWidth= 0.5
dictionary3 = df_compare['main_category'].value_counts().to_dict()
x = dictionary3.keys()
y = dictionary3.values()
plot1 = plt.bar(x, y, width=barWidth)
plt.title('Class Main Category', fontsize = '20')
plt.xlabel('Main Category', fontsize = '20')
plt.ylabel('Count', fontsize = '20')
for bar in plot1:
plt.annotate(bar.get_height(),xy=(bar.get_x(), bar.get_height()+200,), fontsize=10)
Solution 1:[1]
try this :
df_new=df_new.reset_index()
df_new_new = df_new.loc[(df_new['country'].isin(["US", "GB"])), ['ID','name','main_category', 'usd_goal_real','usd_pledge_real','backers','state']]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DataSciRookie |