Skip to content

Commit eca3711

Browse files
authored
Update doc/python/bar-charts.md
1 parent 5e89427 commit eca3711

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: doc/python/bar-charts.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ Stacked bar charts are a powerful way to present results summarizing categories
313313
from plotly import graph_objects as go
314314
import pandas as pd
315315
316-
#get one year of gapminder data
316+
# Get one year of gapminder data
317317
url = 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv'
318318
df = pd.read_csv(url)
319319
df = df[df['year']==2007]
320320
df["gdp"]=df["pop"]*df['gdpPercap']
321321
322322
323-
#build the summary of interest
323+
# Build the summary of interest
324324
df_summarized = df.groupby("continent", observed=True).agg("sum").reset_index()
325325
326326
df_summarized["percent of world population"]=100*df_summarized["pop"]/df_summarized["pop"].sum()
@@ -332,17 +332,17 @@ df = df_summarized[["continent",
332332
"percent of world GDP",
333333
]]
334334
335-
#we now have a wide data frame, but it's in the opposite orientation from the one that px is designed to deal with.
336-
#transposing it and rebuilding the indexes is an option, but iterating through the DF using graph objects is more succinct.
335+
# We now have a wide data frame, but it's in the opposite orientation from the one that px is designed to deal with.
336+
# Transposing it and rebuilding the indexes is an option, but iterating through the DF using graph objects is more succinct.
337337
338338
fig=go.Figure()
339339
for category in df_summarized["continent"].values:
340340
fig.add_trace(go.Bar(
341341
x=df.columns[1:],
342-
#we need to get a pandas series that contains just the values to graph;
343-
#we do so by selecting the right row, selecting the right columns
344-
#and then tranposing and using iloc to convert to a series
345-
#here, I assume that the bar element category variable is in column 0
342+
# We need to get a pandas series that contains just the values to graph;
343+
# We do so by selecting the right row, selecting the right columns
344+
# and then transposing and using iloc to convert to a series
345+
# Here, we assume that the bar element category variable is in column 0
346346
y=list(df.loc[df["continent"]==category][list(df.columns[1:])].transpose().iloc[:,0]),
347347
name=str(category)
348348

0 commit comments

Comments
 (0)