Plotting histogram instead of bar chart
See original GitHub issueI am trying to make a stacked bar graph but when I give a list to the parameter “y” to the function “plotly.express.bar”, plotly creates a histogram instead of a bar chart.
import pandas as pd
import plotly.express as px
tweets = pd.read_csv("Tweets.csv")
tweets.head()
bar = tweets[['airline','airline_sentiment']]
bar.reset_index()
new_df = pd.DataFrame(columns = ["airline", "positive", "negative", "neutral"])
airlines = bar['airline'].unique()
for i in range(len(airlines)):
new_df.loc[len(new_df),'airline']=airlines[i]
x = bar[bar['airline'] == airlines[i]]
new_df.loc[len(new_df)-1,'positive'] = (x['airline_sentiment'] == 'positive').sum()
new_df.loc[len(new_df)-1,'negative'] = len(x[x['airline_sentiment'] == 'negative'])
new_df.loc[len(new_df)-1,'neutral'] = len(x[x['airline_sentiment'] == 'neutral'])
new_df
fig = px.bar(new_df, x = "airline", y = ["positive","negative", "neutral"], title = "Sentiments")
fig.show()
The CSV file and Jupyter notebook are included in the zipped file. StackedBar.zip
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
histogram versus bar graph - storytelling with data
Histograms visualize quantitative data or numerical data, whereas bar charts display categorical variables. In most instances, the numerical ...
Read more >Histogram vs Bar Graph – Difference Between Them - Guru99
The Histogram refers to a graphical representation that shows data by way of bars to display the frequency of numerical data whereas the...
Read more >A Histogram is NOT a Bar Chart - Forbes
Histograms plot quantitative data with ranges of the data grouped into bins or intervals while bar charts plot categorical data.
Read more >Difference Between Histogram and Bar Graph
Histogram refers to a graphical representation; that displays data by way of bars to show the frequency of numerical data. A bar graph...
Read more >Histogram vs bar graph: Which should you use? - ThoughtSpot
Two of the most common charts used to visualize data are bar graphs and histograms. These two can look alike, but they aren't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be nice for Plotly to do this, yes, but it’s more of a data-later responsibility here IMO than a vis-layer concern. If Pandas is unable to get the type right in this case, it’s unlikely that Plotly will be able to do a better job 😃
Yeah, you are right Nicolas.
Anyways, as a programmer, we should be able to debug the problem and your comment helped me in understanding the problem which was great learning for me.