<jupyter_start><jupyter_text>การสร้างแบบ stacked bar ด้วย pandas<jupyter_code>#เรียนรู้ Pandas bar stacked
from IPython.display import IFrame, YouTubeVideo, SVG, HTML
YouTubeVideo('26Nmks3vctU', 400,300)
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter # for custom number format on x and y axis
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
print(f'pandas version: {pd.__version__}')
pd.set_option('display.max_rows', 10)<jupyter_output><empty_output><jupyter_text>PISA score from Wikipediahttps://en.wikipedia.org/wiki/Programme_for_International_Student_Assessment<jupyter_code>df=pd.read_csv('https://github.com/prasertcbs/basic-dataset/raw/master/pisa2015.csv')
df
df[:5].plot(kind='bar', stacked=True);
df.set_index('Country', inplace=True)
df
df[:5].plot(kind='bar', stacked=True, title='PISA score 2015');
df=pd.read_csv('https://github.com/prasertcbs/basic-dataset/raw/master/pisa2015.csv',
               index_col='Country')
df
df[:5].plot(kind='barh', stacked=True, title='PISA score 2015');
df[:5].plot(kind='barh', stacked=True, figsize=(8, 4));
df[:5][['Maths', 'Science']].plot(kind='barh', stacked=True);<jupyter_output><empty_output><jupyter_text>https://matplotlib.org/2.0.0/examples/color/named_colors.html<jupyter_code>ax=df[:5][['Maths', 'Science']].plot(kind='barh', stacked=True, color=['gold', 'c'],
                                    title='PISA Score 2015');
ax.set_xlabel('score')
ax.set_ylabel('');
df['Total'] = df.Maths + df.Science + df.Reading
df
df.nlargest(10, 'Total')[['Maths', 'Science', 'Reading']].plot(kind='barh', stacked=True)
df.loc[['Japan', 'Taiwan', 'Vietnam', 'Thailand'], 
       ['Maths', 'Science', 'Reading']].plot(kind='barh', stacked=True)<jupyter_output><empty_output><jupyter_text>การกำหนดรูปแบบการแสดงตัวเลขในแกน เช่น มีการคั่นด้วย , ในเลขหลักพัน<jupyter_code>ax=df.loc[['Japan', 'Taiwan', 'Vietnam', 'Thailand'], 
          ['Maths', 'Science', 'Reading']].plot(kind='barh', stacked=True,
                                                color=['maroon', 'gold', 'c'],
                                                figsize=(10,5))
ax.xaxis.set_major_formatter(FuncFormatter(lambda v, p: "{:,.0f}".format(v)))
ax.set_xlabel('score')
ax.set_ylabel('');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18552232336367577, 'fraction_numerical': 0.02080624187256177, 'mean_word_length': 5.323287671232877, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '487619', 'license': 'MIT', 'n_tokens_mistral': 944, 'n_tokens_neox': 880, 'n_words': 124, 'path': 'learn_jupyter/7_pandas_stacked_bar_plot.ipynb', 'repo_name': 'langsari/ftu-artificial-intelligence', 'size': '2307'}