<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Jupyter Notebook - MasaruのIT＆マーケティングBLOG | Info Tech &amp; Marketing BLOG by Masaru</title>
	<atom:link href="/tag/jupyter-notebook/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>Cross the cliffs of the times</description>
	<lastBuildDate>Fri, 09 Apr 2021 15:56:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8</generator>
<site xmlns="com-wordpress:feed-additions:1">191177362</site>	<item>
		<title>Jupyter NotebookのセルをWordPressに貼り付ける</title>
		<link>/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b</link>
					<comments>/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/#respond</comments>
		
		<dc:creator><![CDATA[masaru]]></dc:creator>
		<pubDate>Fri, 09 Apr 2021 15:21:30 +0000</pubDate>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Webデザイン]]></category>
		<category><![CDATA[データ分析]]></category>
		<category><![CDATA[Jupyter Notebook]]></category>
		<category><![CDATA[nbconvert]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">/?p=318</guid>

					<description><![CDATA[<p>手作業でJupyter NotebookをWordPressに転記するのはツライ…… 　ということでコピペする方法を探してみたところ、nbconvertを使う方法が良さそうです。 　生成されたHTMLから該当セルをWeb&#8230; <a class="more-link" href="/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/">続きを読む <span class="screen-reader-text">Jupyter NotebookのセルをWordPressに貼り付ける</span></a></p>
<p>The post <a href="/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/">Jupyter NotebookのセルをWordPressに貼り付ける</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></description>
										<content:encoded><![CDATA[<h2>手作業でJupyter NotebookをWordPressに転記するのはツライ……</h2>



<p>　ということでコピペする方法を探してみたところ、<a href="https://datacoach.me/data/tips/jupyter-wordpress/" target="_blank" rel="noreferrer noopener">nbconvertを使う方法</a>が良さそうです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>$ jupyter nbconvert --to html --template basic gstore-cust-revenue-prediction.ipynb</code></pre></div>



<p>　生成されたHTMLから該当セルをWebブラウザーのインスペクター(F12キーを押下)でコピーし、WordPressのカスタムHTMLブロックに貼り込みます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-html" data-lang="HTML"><code>&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;prompt input_prompt&quot;&gt;In [7]:&lt;/div&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pandas&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;seaborn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sns&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;gc&lt;/span&gt;                              &lt;span class=&quot;c1&quot;&gt;#garbage collector&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.preprocessing&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LabelEncoder&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ast&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;literal_eval&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.model_selection&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;KFold&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.metrics&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mean_squared_error&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.model_selection&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GridSearchCV&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#Experimented hyperparams a bit with this&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;catboost&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CatBoostRegressor&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;xgboost&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;XGBRegressor&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;lightgbm&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;lgb&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filenames&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;/home/masaru/data/kaggle_google_analytics&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filenames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;whitegrid&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;palette&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;deep&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;font_scale&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;figure.figsize&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]})&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set_option&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;float_format&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{:f}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;#to display full numbers in dataframe and not just exponentiated form &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;


&lt;div class=&quot;output_area&quot;&gt;

    &lt;div class=&quot;prompt&quot;&gt;&lt;/div&gt;


&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;/home/masaru/data/kaggle_google_analytics/test_v2.csv
/home/masaru/data/kaggle_google_analytics/submission.csv
/home/masaru/data/kaggle_google_analytics/deep-learning-keras-ga-revenue-prediction.ipynb
/home/masaru/data/kaggle_google_analytics/gstore-cust-revenue-prediction.ipynb
/home/masaru/data/kaggle_google_analytics/ga-customer-revenue-prediction.zip
/home/masaru/data/kaggle_google_analytics/test.csv
/home/masaru/data/kaggle_google_analytics/sample_submission_v2.csv
/home/masaru/data/kaggle_google_analytics/GoogleAnalytics_Customer_Revenue_EDA_and_Prediction.ipynb
/home/masaru/data/kaggle_google_analytics/sample_submission.csv
/home/masaru/data/kaggle_google_analytics/train_v2.csv
/home/masaru/data/kaggle_google_analytics/train.csv
/home/masaru/data/kaggle_google_analytics/.ipynb_checkpoints/gstore-cust-revenue-prediction-checkpoint.ipynb
/home/masaru/data/kaggle_google_analytics/.ipynb_checkpoints/GoogleAnalytics_Customer_Revenue_EDA_and_Prediction-checkpoint.ipynb
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/div&gt;</code></pre></div>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>WordPressのテーマにNotebook用のCSSを追加する</h2>



<p>　続いて、WordPressの『外観⇒カスタマイズ⇒追加CSS』で<a href="https://estuarine.jp/2017/09/jupyter-wordpress/" target="_blank" rel="noreferrer noopener">Jupyter Notebookセル用のCSS</a>を追加します(リンク先ページのソースを参照のこと)。</p>



<div class="input">
<div class="prompt input_prompt">In&nbsp;[7]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span><span class="o">,</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span><span class="o">,</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span><span class="o">,</span> <span class="nn">seaborn</span> <span class="k">as</span> <span class="nn">sns</span>
<span class="kn">import</span> <span class="nn">json</span><span class="o">,</span> <span class="nn">re</span><span class="o">,</span> <span class="nn">gc</span>                              <span class="c1">#garbage collector</span>
<span class="kn">from</span> <span class="nn">sklearn.preprocessing</span> <span class="kn">import</span> <span class="n">LabelEncoder</span>
<span class="kn">from</span> <span class="nn">ast</span> <span class="kn">import</span> <span class="n">literal_eval</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">KFold</span>
<span class="kn">from</span> <span class="nn">sklearn.metrics</span> <span class="kn">import</span> <span class="n">mean_squared_error</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">GridSearchCV</span> <span class="c1">#Experimented hyperparams a bit with this</span>

<span class="kn">from</span> <span class="nn">catboost</span> <span class="kn">import</span> <span class="n">CatBoostRegressor</span>
<span class="kn">from</span> <span class="nn">xgboost</span> <span class="kn">import</span> <span class="n">XGBRegressor</span>
<span class="kn">import</span> <span class="nn">lightgbm</span> <span class="k">as</span> <span class="nn">lgb</span>

<span class="k">for</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">filenames</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s1">'/home/masaru/data/kaggle_google_analytics'</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">filenames</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span> <span class="n">filename</span><span class="p">))</span>
        <span class="k">pass</span>
<span class="n">gc</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>
<span class="n">sns</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">style</span><span class="o">=</span><span class="s1">'whitegrid'</span><span class="p">,</span><span class="n">palette</span><span class="o">=</span><span class="s1">'deep'</span><span class="p">,</span><span class="n">font_scale</span><span class="o">=</span><span class="mf">1.1</span><span class="p">,</span><span class="n">rc</span><span class="o">=</span><span class="p">{</span><span class="s1">'figure.figsize'</span><span class="p">:[</span><span class="mi">8</span><span class="p">,</span><span class="mi">6</span><span class="p">]})</span>
<span class="n">pd</span><span class="o">.</span><span class="n">set_option</span><span class="p">(</span><span class="s1">'float_format'</span><span class="p">,</span> <span class="s1">'</span><span class="si">{:f}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">)</span>     <span class="c1">#to display full numbers in dataframe and not just exponentiated form </span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<pre>/home/masaru/data/kaggle_google_analytics/test_v2.csv
/home/masaru/data/kaggle_google_analytics/submission.csv
/home/masaru/data/kaggle_google_analytics/deep-learning-keras-ga-revenue-prediction.ipynb
/home/masaru/data/kaggle_google_analytics/gstore-cust-revenue-prediction.ipynb
/home/masaru/data/kaggle_google_analytics/ga-customer-revenue-prediction.zip
/home/masaru/data/kaggle_google_analytics/test.csv
/home/masaru/data/kaggle_google_analytics/sample_submission_v2.csv
/home/masaru/data/kaggle_google_analytics/GoogleAnalytics_Customer_Revenue_EDA_and_Prediction.ipynb
/home/masaru/data/kaggle_google_analytics/sample_submission.csv
/home/masaru/data/kaggle_google_analytics/train_v2.csv
/home/masaru/data/kaggle_google_analytics/train.csv
/home/masaru/data/kaggle_google_analytics/.ipynb_checkpoints/gstore-cust-revenue-prediction-checkpoint.ipynb
/home/masaru/data/kaggle_google_analytics/.ipynb_checkpoints/GoogleAnalytics_Customer_Revenue_EDA_and_Prediction-checkpoint.ipynb
</pre>
</div>
</div>

</div>
</div>



<p>　無事、表示出来ました。</p>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="いいねボタン"
					data-ulike-id="318"
					data-ulike-nonce="30df098a0b"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_318"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="0"></span>			</div></div>
	<p><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_line" href="https://www.addtoany.com/add_to/line?linkurl=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" title="Line" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook_messenger" href="https://www.addtoany.com/add_to/facebook_messenger?linkurl=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" title="Messenger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_copy_link" href="https://www.addtoany.com/add_to/copy_link?linkurl=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" title="Copy Link" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=%2F2021%2F04%2F10%2Fjupyter-notebook%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2582%2592wordpress%25e3%2581%25ab%25e8%25b2%25bc%25e3%2582%258a%25e4%25bb%2598%25e3%2581%2591%25e3%2582%258b%2F&#038;title=Jupyter%20Notebook%E3%81%AE%E3%82%BB%E3%83%AB%E3%82%92WordPress%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B" data-a2a-url="/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/" data-a2a-title="Jupyter NotebookのセルをWordPressに貼り付ける"></a></p><p>The post <a href="/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/">Jupyter NotebookのセルをWordPressに貼り付ける</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2021/04/10/jupyter-notebook%e3%81%ae%e3%82%bb%e3%83%ab%e3%82%92wordpress%e3%81%ab%e8%b2%bc%e3%82%8a%e4%bb%98%e3%81%91%e3%82%8b/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">318</post-id>	</item>
		<item>
		<title>Jupyter NotebookからPythonでPostgreSQL 13を操作する</title>
		<link>/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b</link>
					<comments>/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/#respond</comments>
		
		<dc:creator><![CDATA[masaru]]></dc:creator>
		<pubDate>Wed, 07 Apr 2021 10:49:51 +0000</pubDate>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[データ分析]]></category>
		<category><![CDATA[Anaconda]]></category>
		<category><![CDATA[Jupyter Notebook]]></category>
		<category><![CDATA[Plotly]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL 13]]></category>
		<category><![CDATA[psycopg2]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">/?p=208</guid>

					<description><![CDATA[<p>まずは堅実に定番RDBから 　NoSQLブームで勉強会界隈では影が薄れた感があるRDBMSですが、当たり前の存在になっただけで健在です。当サイトが使っているCMS『WordPress』にはMySQLが組み込まれていますし&#8230; <a class="more-link" href="/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/">続きを読む <span class="screen-reader-text">Jupyter NotebookからPythonでPostgreSQL 13を操作する</span></a></p>
<p>The post <a href="/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/">Jupyter NotebookからPythonでPostgreSQL 13を操作する</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></description>
										<content:encoded><![CDATA[<h2>まずは堅実に定番RDBから</h2>



<p>　NoSQLブームで勉強会界隈では影が薄れた感があるRDBMSですが、当たり前の存在になっただけで健在です。当サイトが使っているCMS『WordPress』にはMySQLが組み込まれていますし、当サイトを置いているAWSでも<a href="https://aws.amazon.com/jp/blogs/news/accelerate-amazon-redshift-federated-query-adoption-with-aws-cloudformation/" target="_blank" rel="noreferrer noopener">PostgreSQLがRedShiftやAuroraなど基幹サービスで使われています</a>。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="731" height="486" src="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AccelerateRedshiftFederatedQuery1.png?resize=731%2C486&#038;ssl=1" alt="" class="wp-image-291" srcset="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AccelerateRedshiftFederatedQuery1.png?w=731&amp;ssl=1 731w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AccelerateRedshiftFederatedQuery1.png?resize=300%2C199&amp;ssl=1 300w" sizes="(max-width: 731px) 100vw, 731px" data-recalc-dims="1" /></figure>



<p>　統計モデリングを知らないのにディープラーニングでイキる人が信用出来ないのと同様、RDBMSを知らないのにNoSQLを語るのもイタい人です。私も昨年は<a href="https://www.elastic.co/jp/elasticsearch/" target="_blank" rel="noreferrer noopener">Elasticsearch</a>などのNoSQLや<a href="https://ignite.apache.org/" target="_blank" rel="noreferrer noopener">Apache Ignite</a>などの分散データベースにハマっていましたが、自分のイタさに気づいたためPostgreSQLを学び直しています。</p>



<p>　NoSQLや分散データベースを業務で使いこなしている方々の講演は勉強会で聞くことが出来ますが、彼らは「RDBMSを経験した上でNoSQLに進んでいる」のです。未経験者が講演を聞いていきなりNoSQLに行くのは『悪手』です。</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>初心者がNoSQLや分散RDBでやりたいことはPostgreSQLでも出来ている</h2>



<p>　NoSQLが主に扱うJSONはPosgreSQLでも『<a href="https://www.postgresql.org/docs/13/datatype-json.html" target="_blank" rel="noreferrer noopener">JSON型</a>』として扱えます。IMDBで話題となったインメモリ処理はPostgreSQLでも<a href="https://techblog.gmo-ap.jp/2020/11/25/postgresql_memory_architecture/" target="_blank" rel="noreferrer noopener">駆使されています</a>。分散データベースの特徴であるクエリの並列処理はPostgreSQLでも<a href="https://oss-db.jp/dojo/dojo_column_04" target="_blank" rel="noreferrer noopener">パラレルクエリ</a>として実装されている上、特別の設定無しで自動的に使ってくれます。</p>



<p>　昨年、実際にApage IgniteでPCサーバ5台のクラスタを構築しましたが、数10GB程度のデータではクエリに要する時間がシングルノードのPostgreSQLの方が速かったです。2.5GbEでもLANの遅延で並列処理のメリットが相殺されてしまいます。この規模のデータでクエリを高速化するなら、<a href="https://www.tsukumo.co.jp/bto/pc/workstation/2021/WA9A-G210WT.html" target="_blank" rel="noreferrer noopener">32コア64スレッドのパソコン</a>でも買えば良いと思います。</p>



<p>　こういう事実は、基本的すぎて勉強会ではなかなか教えてもらえないですね。エンジニアの方にとっては常識なのでしょうが……<img src="https://s.w.org/images/core/emoji/13.1.0/72x72/1f4a6.png" alt="💦" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>PythonでPostgreSQLを扱うパッケージ『psycopg2』</h2>



<p>　PythonでPostgreSQLを扱う際は『psycopg2』というパッケージを使うのが一般的なようです。視覚化のためのパッケージ『Plotly』と併せてインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>(base) masaru@ASUS-TUF-Gaming:~$ conda install psycopg2
(base) masaru@ASUS-TUF-Gaming:~$ conda install plotly</code></pre></div>



<h2>Jupyter Notebookでの実装</h2>



<p>　必要なパッケージの読み込みなどの初期設定を行います。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code># -*- coding: utf-8 -*-
import psycopg2
import pandas as pd
import plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()</code></pre></div>



<p>　psychopg2でデータベース接続を定義します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>def connect():
    con = psycopg2.connect(&quot;host=&quot; + &quot;localhost&quot; +
                           &quot; port=&quot; + &quot;5432&quot; +
                           &quot; dbname=&quot; + &quot;google_mobility&quot; +
                           &quot; user=&quot; + &quot;masaru&quot; +
                           &quot; password=&quot; + &quot;xxxxxxxxxxxx&quot;)
    return con</code></pre></div>



<p>　続いて、クエリを定義します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>def select_execute(con, sql):
    with con.cursor() as cur:
        cur.execute(sql)
        rows = cur.fetchall()

    return rows</code></pre></div>



<p>　定義したクエリを実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>con = connect()
sql =  &quot;select * from google_mobility where SUB_REGION_1 = &#39;Tokyo&#39;&quot;
result = select_execute(con, sql)</code></pre></div>



<p>　クエリの結果をPandasデータフレームに代入します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>df = pd.DataFrame(result)
df.head()</code></pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" width="737" height="159" src="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg06.png?resize=737%2C159&#038;ssl=1" alt="" class="wp-image-293" srcset="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg06.png?w=737&amp;ssl=1 737w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg06.png?resize=300%2C65&amp;ssl=1 300w" sizes="(max-width: 737px) 100vw, 737px" data-recalc-dims="1" /></figure>



<p>　とりあえず全部カラム名をつけてあげます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>columns = [&quot;id&quot;,&quot;country_region_code&quot;,&quot;country_region&quot;,&quot;sub_region_1&quot;,&quot;sub_region_2&quot;,&quot;metro_area&quot;,&quot;iso_3166_2_code&quot;,&quot;census_fips_code&quot;,&quot;date&quot;,&quot;retail&quot;,&quot;grocery&quot;,&quot;parks&quot;,&quot;transit&quot;,&quot;workplaces&quot;,&quot;residental&quot;,&quot;place_id&quot;]
df.columns = columns
df.head()</code></pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="132" src="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg09.png?resize=750%2C132&#038;ssl=1" alt="" class="wp-image-295" srcset="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg09.png?w=996&amp;ssl=1 996w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg09.png?resize=300%2C53&amp;ssl=1 300w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg09.png?resize=768%2C135&amp;ssl=1 768w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /></figure>



<p>　Plotlyで表示するデータを設定します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>trace1 = go.Scatter(
        x = list(df.date),
        y = list(df.retail),
        mode = &#39;lines+markers&#39;,
        name = &#39;retail&#39;,
        marker = dict(
                color = &#39;blue&#39;
                )
        )

trace2 = go.Scatter(
        x = list(df.date),
        y = list(df.grocery),
        mode = &#39;lines+markers&#39;,
        name = &#39;grocery&#39;,
        marker = dict(
                color = &#39;orange&#39;
                )
        )

data = [trace1, trace2]</code></pre></div>



<p>　続いて、Plotlyの特長であるスライダーを設定します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>layout = dict(
    title=&#39;Time series with range slider and selectors&#39;,
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label=&#39;1m&#39;,
                     step=&#39;month&#39;,
                     stepmode=&#39;backward&#39;),
                dict(count=6,
                     label=&#39;6m&#39;,
                     step=&#39;month&#39;,
                     stepmode=&#39;backward&#39;),
                dict(count=1,
                    label=&#39;YTD&#39;,
                    step=&#39;year&#39;,
                    stepmode=&#39;todate&#39;),
                dict(count=1,
                    label=&#39;1y&#39;,
                    step=&#39;year&#39;,
                    stepmode=&#39;backward&#39;),
                dict(step=&#39;all&#39;)
            ])
        ),
        rangeslider=dict(
            visible = True
        ),
        type=&#39;date&#39;
    )
)</code></pre></div>



<p>　グラフを描画します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>fig = dict(data=data, layout=layout)
iplot(fig)</code></pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="348" src="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg13.png?resize=750%2C348&#038;ssl=1" alt="" class="wp-image-296" srcset="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg13.png?w=945&amp;ssl=1 945w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg13.png?resize=300%2C139&amp;ssl=1 300w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/pypg13.png?resize=768%2C357&amp;ssl=1 768w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /></figure>



<p>　スライダーを動かせるグラフの出来上がりです。</p>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="いいねボタン"
					data-ulike-id="208"
					data-ulike-nonce="c61a6e13bb"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_208"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="0"></span>			</div></div>
	<p><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_line" href="https://www.addtoany.com/add_to/line?linkurl=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" title="Line" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook_messenger" href="https://www.addtoany.com/add_to/facebook_messenger?linkurl=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" title="Messenger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_copy_link" href="https://www.addtoany.com/add_to/copy_link?linkurl=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;linkname=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" title="Copy Link" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=%2F2021%2F04%2F07%2Fjupyter-notebook%25e3%2581%258b%25e3%2582%2589python%25e3%2581%25a7postgresql-13%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&#038;title=Jupyter%20Notebook%E3%81%8B%E3%82%89Python%E3%81%A7PostgreSQL%2013%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B" data-a2a-url="/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/" data-a2a-title="Jupyter NotebookからPythonでPostgreSQL 13を操作する"></a></p><p>The post <a href="/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/">Jupyter NotebookからPythonでPostgreSQL 13を操作する</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2021/04/07/jupyter-notebook%e3%81%8b%e3%82%89python%e3%81%a7postgresql-13%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">208</post-id>	</item>
		<item>
		<title>Ubuntu 21.04使用開始(1日目)</title>
		<link>/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae</link>
					<comments>/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/#respond</comments>
		
		<dc:creator><![CDATA[masaru]]></dc:creator>
		<pubDate>Mon, 05 Apr 2021 08:13:48 +0000</pubDate>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[PC & Mobile]]></category>
		<category><![CDATA[Anaconda]]></category>
		<category><![CDATA[DBeaver]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[Jupyter Notebook]]></category>
		<category><![CDATA[Krita]]></category>
		<category><![CDATA[NVIDIA]]></category>
		<category><![CDATA[OpenJDK 11]]></category>
		<category><![CDATA[RStudio]]></category>
		<category><![CDATA[Ryzen]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Ubuntu 21.04]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<guid isPermaLink="false">/?p=164</guid>

					<description><![CDATA[<p>Ryzen+NVIDIAのノートが欲しい。データベースと機械学習の全部入りラーメンだ 　前々から、図書館などでもガッツリ使い倒せるLinuxノートが欲しいと思っていました。具体的には、PostgreSQLがselect文&#8230; <a class="more-link" href="/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/">続きを読む <span class="screen-reader-text">Ubuntu 21.04使用開始(1日目)</span></a></p>
<p>The post <a href="/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/">Ubuntu 21.04使用開始(1日目)</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></description>
										<content:encoded><![CDATA[<h2>Ryzen+NVIDIAのノートが欲しい。データベースと機械学習の全部入りラーメンだ</h2>



<p>　前々から、図書館などでもガッツリ使い倒せるLinuxノートが欲しいと思っていました。具体的には、PostgreSQLがselect文で4スレッドくらい並列処理してくれて、TensorFlow/KerasでGPU SUGEEEE出来る程度のスペックです。</p>



<p>　Amazonの年末セールで『ASUS ゲーミングノートパソコン TUF Gaming A15 FA506IH (AMD Ryzen5 4600H/8GB・SSD 512GB/GTX 1650/1,920×1,080ドット (フルHD) (144Hz)/15.6インチ/フォートレス・グレイ)』が￥82,800と安かったので衝動買い。メモリは即32GBに増設しました。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="677" height="288" src="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/TUF-amzon.png?resize=677%2C288&#038;ssl=1" alt="" class="wp-image-172" srcset="https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/TUF-amzon.png?w=677&amp;ssl=1 677w, https://i2.wp.com/can.ne.jp/wp-content/uploads/2021/04/TUF-amzon.png?resize=300%2C128&amp;ssl=1 300w" sizes="(max-width: 677px) 100vw, 677px" data-recalc-dims="1" /><figcaption>「AMDが7nmで作ったワットパフォーマンスが良いRenoirが載ったノートにディープラーニングで使えるGTX 1650が付いて8万ちょい。買うしかない……」</figcaption></figure>



<p>　4600Hは6コア12スレッドのノートPC向けCPUで、AMD Renoirシリーズの廉価版です。『最強』ではありませんが、実売10万円以下のノートでこの性能は魅力的です。SSDは内蔵で別途2TBくらい欲しいですが、金欠なので追い詰まってから考えることにします。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="538" src="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AMD_Ryzen5_4600H.png?resize=750%2C538&#038;ssl=1" alt="" class="wp-image-185" srcset="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AMD_Ryzen5_4600H.png?resize=1024%2C735&amp;ssl=1 1024w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AMD_Ryzen5_4600H.png?resize=300%2C215&amp;ssl=1 300w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AMD_Ryzen5_4600H.png?resize=768%2C551&amp;ssl=1 768w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/AMD_Ryzen5_4600H.png?w=1333&amp;ssl=1 1333w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /><figcaption>AMD Ryzen 5 4600Hは7nm世代の廉価版モバイルCPU</figcaption></figure>



<p>　なお現在の最新モデルは「Ryzen PRO 5000シリーズ モバイル プロセッサ(5850U/5650U/5450U)」、及び「Ryzen 5000シリーズ モバイル プロセッサ(5800U/5700U/5600U/5500U/5400U/5300U)」で7nm世代のままです。5nmのZen4世代は2022年に登場予定です。</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>ゲーミングPCへのUbuntu 21.04のインストール</h2>



<p> 　Ubuntuのインストールが終わると、沢山の有名で楽しそうなアプリをリコメンドされます。「SSDの残りが300GBくらいしかないのに片っ端から入れちゃダメダ」と思いつつも入れられるうちはつい入れてしまいます。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="556" src="https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/recommend_apps_by_ubuntu.png?resize=750%2C556&#038;ssl=1" alt="" class="wp-image-173" srcset="https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/recommend_apps_by_ubuntu.png?w=977&amp;ssl=1 977w, https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/recommend_apps_by_ubuntu.png?resize=300%2C222&amp;ssl=1 300w, https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/recommend_apps_by_ubuntu.png?resize=768%2C569&amp;ssl=1 768w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2> 日本語フォルダ名を英語化</h2>



<p>　lsなどでパス指定するときにフォルダ名が日本語だとIMEの切り替えや入力が面倒なので、英語に変えてしまいます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>masaru@ASUS-TUF-Gaming:~$ LANG=C xdg-user-dirs-gtk-update</code></pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="444" src="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/Japanese_folders_to_English.pngJ_.png?resize=750%2C444&#038;ssl=1" alt="" class="wp-image-176" srcset="https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/Japanese_folders_to_English.pngJ_.png?w=974&amp;ssl=1 974w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/Japanese_folders_to_English.pngJ_.png?resize=300%2C177&amp;ssl=1 300w, https://i0.wp.com/can.ne.jp/wp-content/uploads/2021/04/Japanese_folders_to_English.pngJ_.png?resize=768%2C454&amp;ssl=1 768w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>導入直後に入れたアプリ</h2>



<p>　初心者でも導入に困らなさそうなものは名前だけ……。</p>



<figure class="wp-block-table is-style-stripes"><table><tbody><tr><td>NVIDIA driver metapackage</td><td>NVIDIA独自のグラフィックドライバ。『ソフトウェアとアップデート』 &#8211; 『追加のドライバー』でプロプライエタリ版を指定してインストールする必要がある</td></tr><tr><td>Ubuntu Live Patch</td><td>パッケージの自動更新サービス。実際は手動でapt updateを続けることが多いですが、念のため導入</td></tr><tr><td><s>Shutter</s></td><td>画面キャプチャソフト。不具合のため現在使用できず</td></tr><tr><td>Krita</td><td>定番の画像ソフト。Shutterが使えなかったので最優先で導入。個人的にも好きなソフト</td></tr><tr><td>Google Chrome, Chromium</td><td>Webブラウザ。SSOの誘惑と逃げたい気持ちでサンドイッチに</td></tr><tr><td>dbeaver-ce</td><td>JDBCの汎用データベースクライアント</td></tr><tr><td>Anaconda</td><td>言わずと知れたPython機械学習系のフレームワーク。PATHを汚染するので好きではないのですが、楽なので結局入れてしまいます</td></tr><tr><td>jupyter-notebook</td><td>Anacondaに同梱のPython実行環境</td></tr><tr><td>Visual Studio Code</td><td>プログラム開発環境のデファクトスタンダード。Pythonなどのインタプリタを配下に置いてしまうAnacondaとの共存が課題</td></tr><tr><td>R</td><td>Anacondaのパッケージとしてcondaでインストール</td></tr><tr><td>RStudio</td><td>Rの開発環境。PATHの問題を避けるためAnacondaからインストール</td></tr><tr><td>traceroute</td><td>サーバーまでのネットワーク経路を確認するツール</td></tr><tr><td>OpenJDK 11</td><td>各種データベース用のJava開発環境</td></tr></tbody></table></figure>



<h2>NDIVIAドライバの基本設定</h2>



<p>　Ubuntu 21.04は、素の状態でNVIDIAの独自ドライバを使ってくれません。チューニングの観点から独自ドライバを入れるのが良さそうです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>masaru@ASUS-TUF-Gaming:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation TU117M (rev ff)
01:00.1 Audio device: NVIDIA Corporation Device 10fa (rev ff)</code></pre></div>



<figure class="wp-block-image size-large"><img loading="lazy" width="750" height="386" src="https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/NVIDIA_driver_selection.png?resize=750%2C386&#038;ssl=1" alt="" class="wp-image-174" srcset="https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/NVIDIA_driver_selection.png?w=992&amp;ssl=1 992w, https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/NVIDIA_driver_selection.png?resize=300%2C154&amp;ssl=1 300w, https://i1.wp.com/can.ne.jp/wp-content/uploads/2021/04/NVIDIA_driver_selection.png?resize=768%2C395&amp;ssl=1 768w" sizes="(max-width: 750px) 100vw, 750px" data-recalc-dims="1" /></figure>



<p> 　続いて、aptのレポジトリに最新のドライバが降ってくるように設定します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>masaru@ASUS-TUF-Gaming:~$ sudo add-apt-repository -y -n ppa:graphics-drivers/ppaPPA publishes dbgsym, you may need to include &#39;main/debug&#39; component
Repository: &#39;deb http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu/ hirsute main&#39;
Description:
Fresh drivers from upstream, currently shipping Nvidia.

## Current Status

Current long-lived branch release: `nvidia-430` (430.40)
Dropped support for Fermi series (https://nvidia.custhelp.com/app/answers/detail/a_id/4656)

Old long-lived branch release: `nvidia-390` (390.129)

For GF1xx GPUs use `nvidia-390` (390.129)
For G8x, G9x and GT2xx GPUs use `nvidia-340` (340.107)
For NV4x and G7x GPUs use `nvidia-304` (304.137) End-Of-Life!

Support timeframes for Unix legacy GPU releases:
https://nvidia.custhelp.com/app/answers/detail/a_id/3142

## What we&#39;re working on right now:

- Normal driver updates
- Help Wanted: Mesa Updates for Intel/AMD users, ping us if you want to help do this work, we&#39;re shorthanded.

## WARNINGS:

This PPA is currently in testing, you should be experienced with packaging before you dive in here:

Volunteers welcome!

### How you can help:

## Install PTS and benchmark your gear:

    sudo apt-get install phoronix-test-suite

Run the benchmark:

    phoronix-test-suite default-benchmark openarena xonotic tesseract gputest unigine-valley

and then say yes when it asks you to submit your results to openbechmarking.org. Then grab a cup of coffee, it takes a bit for the benchmarks to run. Depending on the version of Ubuntu you&#39;re using it might preferable for you to grabs PTS from upstream directly: http://www.phoronix-test-suite.com/?k=downloads

## Share your results with the community:

Post a link to your results (or any other feedback to): https://launchpad.net/~graphics-drivers-testers

Remember to rerun and resubmit the benchmarks after driver upgrades, this will allow us to gather a bunch of data on performance that we can share with everybody.

If you run into old documentation referring to other PPAs, you can help us by consolidating references to this PPA.

If someone wants to go ahead and start prototyping on `software-properties-gtk` on what the GUI should look like, please start hacking!

## Help us Help You!

We use the donation funds to get the developers hardware to test and upload these drivers, please consider donating to the &quot;community&quot; slider on the donation page if you&#39;re loving this PPA:

http://www.ubuntu.com/download/desktop/contribute
More info: https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
Adding repository.
Adding deb entry to /etc/apt/sources.list.d/graphics-drivers-ubuntu-ppa-hirsute.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/graphics-drivers-ubuntu-ppa-hirsute.list
Adding key to /etc/apt/trusted.gpg.d/graphics-drivers-ubuntu-ppa.gpg with fingerprint 2388FF3BE10A76F638F80723FCAE110B1118213C
</code></pre></div>



<h2>Linux版のAnacondaはシェルから導入</h2>



<p>　Anacondaはパスなど各種設定をOSから乗っ取る『お行儀が悪いフレームワーク』なためか、Ubuntuでもストアアプリには入っていません。シェルスクリプトを落としてbashで実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>masaru@ASUS-TUF-Gaming:~/Downloads$ bash ./Anaconda3-2020.11-Linux-x86_64.sh 

Welcome to Anaconda3 2020.11

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
...</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>masaru@ASUS-TUF-Gaming:~/anaconda3/bin$ ./conda init
no change     /home/masaru/anaconda3/condabin/conda
no change     /home/masaru/anaconda3/bin/conda
no change     /home/masaru/anaconda3/bin/conda-env
no change     /home/masaru/anaconda3/bin/activate
no change     /home/masaru/anaconda3/bin/deactivate
no change     /home/masaru/anaconda3/etc/profile.d/conda.sh
no change     /home/masaru/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/masaru/anaconda3/shell/condabin/Conda.psm1
no change     /home/masaru/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/masaru/anaconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change     /home/masaru/anaconda3/etc/profile.d/conda.csh
modified      /home/masaru/.bashrc</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>(base) masaru@ASUS-TUF-Gaming:~$ conda update --all
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/masaru/anaconda3


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _anaconda_depends-2020.07  |           py38_0           6 KB
...</code></pre></div>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>Anacondaの功罪</h2>



<p>　今回インストールしたAnacondaは2020年7月版。主な開発ツールのPATHを乗っ取る仕様であることを考えると半年以上放置されているのは少し疑念を感じます。もちろんconda updateはかけるのですが……。</p>



<p>　最新版をいち早く使いたい方はAnaconda無しのアカウントを作るか、仮想環境で運用することになりそうです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>(base) masaru@ASUS-TUF-Gaming:~$ python --version
Python 3.8.8</code></pre></div>
		<div class="wpulike wpulike-default " ><div class="wp_ulike_general_class wp_ulike_is_not_liked"><button type="button"
					aria-label="いいねボタン"
					data-ulike-id="164"
					data-ulike-nonce="7d79581659"
					data-ulike-type="post"
					data-ulike-template="wpulike-default"
					data-ulike-display-likers=""
					data-ulike-likers-style="popover"
					class="wp_ulike_btn wp_ulike_put_image wp_post_btn_164"></button><span class="count-box wp_ulike_counter_up" data-ulike-counter-value="0"></span>			</div></div>
	<p><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&amp;linkname=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_line" href="https://www.addtoany.com/add_to/line?linkurl=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&amp;linkname=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" title="Line" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&amp;linkname=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook_messenger" href="https://www.addtoany.com/add_to/facebook_messenger?linkurl=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&amp;linkname=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" title="Messenger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_copy_link" href="https://www.addtoany.com/add_to/copy_link?linkurl=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&amp;linkname=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" title="Copy Link" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=%2F2021%2F04%2F05%2Fubuntu-21-04%25e4%25bd%25bf%25e7%2594%25a8%25e9%2596%258b%25e5%25a7%258b1%25e6%2597%25a5%25e7%259b%25ae%2F&#038;title=Ubuntu%2021.04%E4%BD%BF%E7%94%A8%E9%96%8B%E5%A7%8B%281%E6%97%A5%E7%9B%AE%29" data-a2a-url="/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/" data-a2a-title="Ubuntu 21.04使用開始(1日目)"></a></p><p>The post <a href="/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/">Ubuntu 21.04使用開始(1日目)</a> first appeared on <a href="/">MasaruのIT＆マーケティングBLOG  |  Info Tech & Marketing BLOG by Masaru</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2021/04/05/ubuntu-21-04%e4%bd%bf%e7%94%a8%e9%96%8b%e5%a7%8b1%e6%97%a5%e7%9b%ae/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">164</post-id>	</item>
	</channel>
</rss>
