<?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/"
	>

<channel>
	<title>jupyter Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/jupyter/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/jupyter/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Fri, 16 Dec 2022 14:08:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>2021 &#8211; Advent of code &#8211; Day 1</title>
		<link>https://creatronix.de/2021-advent-of-code-day-1/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 02 Dec 2021 09:30:22 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[advent of code]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[jupyter]]></category>
		<category><![CDATA[pandas]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=4285</guid>

					<description><![CDATA[<p>I&#8217;ve haven&#8217;t participated in the advent of code before. But always been curious. What is advent of code? It&#8217;s an advent Calendar for programmers. You get 25 challenges starting December 1st. Caveat: you have to solve the challenge to be eligible for the next day&#8217;s challenge 🙂 Day 1 Challenge &#8211; Part 1 On the&#8230;</p>
<p>The post <a href="https://creatronix.de/2021-advent-of-code-day-1/">2021 &#8211; Advent of code &#8211; Day 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve haven&#8217;t participated in the <a href="https://adventofcode.com/2021/day/1">advent of code</a> before. But always been curious.</p>
<h2>What is advent of code?</h2>
<p>It&#8217;s an <span class="Y2IQFc" lang="en">advent Calendar for programmers. You get 25 challenges starting December 1st. Caveat: you have to solve the challenge to be eligible for the next day&#8217;s challenge 🙂<br />
</span><span id="more-4285"></span></p>
<h2>Day 1 Challenge &#8211; Part 1</h2>
<p>On the first day your first task is to count how many times a value is bigger than its predecessor. They give us some sample data</p>
<pre>199 N/A
200 <strong>bigger</strong>
208 <strong>bigger</strong>
210 <strong>bigger</strong>
200 smaller
207 <strong>bigger</strong>
240 <strong>bigger</strong>
269 <strong>bigger</strong>
260 smaller
263 <strong>bigger</strong></pre>
<p>When we count the times a value is bigger we get seven times bigger.</p>
<p>The actual data contains 2000 rows. This isn&#8217;t exactly big data but I&#8217;ve wanted to dust off my Pandas skill, so here we go:</p>
<p>Let&#8217;s look at the data</p>
<pre>import pandas as pd

df = pd.read_csv("./aoc_day_01_data.txt", header=None)
df.describe</pre>
<p>With the read_csv() function we can read in our data file and convert it into a data frame. It&#8217;s important to hand over the header=None. Otherwise pandas assumes the first row is a column header.</p>
<p>df.describe gives us:</p>
<pre class="console_text">&lt;bound method NDFrame.describe of          0
0      159
1      158
2      174
3      196
4      197
...    ...
1995  8538
1996  8543
1997  8545
1998  8557
1999  8568

[2000 rows x 1 columns]&gt;</pre>
<p>Because we want to reference the columns by name we add a column header</p>
<pre>df.columns = ["original"]</pre>
<p>To compare the nth cell with its n+1th cell neighbour be add a new column but shift the values</p>
<pre>df['shifted'] = df['original'].shift(-1)</pre>
<p>The output looks like this:</p>
<table class="dataframe" border="1">
<thead>
<tr>
<th></th>
<th>original</th>
<th>shifted</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>159</td>
<td><strong>158</strong>.0</td>
</tr>
<tr>
<th>1</th>
<td><strong>158</strong></td>
<td>174.0</td>
</tr>
<tr>
<th>2</th>
<td>174</td>
<td>196.0</td>
</tr>
<tr>
<th>3</th>
<td>196</td>
<td>197.0</td>
</tr>
<tr>
<th>4</th>
<td>197</td>
<td>194.0</td>
</tr>
<tr>
<th>&#8230;</th>
<td>&#8230;</td>
<td>&#8230;</td>
</tr>
<tr>
<th>1995</th>
<td>8538</td>
<td>8543.0</td>
</tr>
<tr>
<th>1996</th>
<td>8543</td>
<td>8545.0</td>
</tr>
<tr>
<th>1997</th>
<td>8545</td>
<td>8557.0</td>
</tr>
<tr>
<th>1998</th>
<td>8557</td>
<td>8568.0</td>
</tr>
<tr>
<th>1999</th>
<td>8568</td>
<td>NaN</td>
</tr>
</tbody>
</table>
<p>We add another column where we place the value True when the value from the current row in the shifted column is bigger than in the original column:</p>
<pre>df['increased'] = (df['shifted'] &gt; df['original'])</pre>
<p>Now it starts to look like the sample data from the introduction:</p>
<table class="dataframe" border="1">
<thead>
<tr>
<th></th>
<th>original</th>
<th>shifted</th>
<th>increased</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>159</td>
<td>158.0</td>
<td>False</td>
</tr>
<tr>
<th>1</th>
<td>158</td>
<td>174.0</td>
<td>True</td>
</tr>
<tr>
<th>2</th>
<td>174</td>
<td>196.0</td>
<td>True</td>
</tr>
<tr>
<th>3</th>
<td>196</td>
<td>197.0</td>
<td>True</td>
</tr>
<tr>
<th>4</th>
<td>197</td>
<td>194.0</td>
<td>False</td>
</tr>
<tr>
<th>&#8230;</th>
<td>&#8230;</td>
<td>&#8230;</td>
<td>&#8230;</td>
</tr>
<tr>
<th>1995</th>
<td>8538</td>
<td>8543.0</td>
<td>True</td>
</tr>
<tr>
<th>1996</th>
<td>8543</td>
<td>8545.0</td>
<td>True</td>
</tr>
<tr>
<th>1997</th>
<td>8545</td>
<td>8557.0</td>
<td>True</td>
</tr>
<tr>
<th>1998</th>
<td>8557</td>
<td>8568.0</td>
<td>True</td>
</tr>
<tr>
<th>1999</th>
<td>8568</td>
<td>NaN</td>
<td>False</td>
</tr>
</tbody>
</table>
<p>the last thing we have to do is counting how many times True occurs:</p>
<pre>true_count = df['increased'].sum()</pre>
<p>which gives us &#8220;1583&#8221;</p>
<p>This is a bit of a hack because it assumes that True equals 1 and False == 0</p>
<p>A more elegant solution is to use value_counts:</p>
<pre>df['increased'].value_counts(dropna=False)</pre>
<p>No the output is:</p>
<pre class="console_text">True     1583
False     417
Name: increased, dtype: int64</pre>
<p>And 1583 is the number we are looking for. This earned us our first golden star and unlocked the second part of the challenge:</p>
<h2>Part 2</h2>
<p>The second part is a bit more challenging because we have to sum up three adjacent values and compare them to the next three values.</p>
<pre>199  A       
200  A B     
208  A B C   
210    B C D
200  E   C D
207  E F   D
240  E F G
269    F G H
260      G H
263        H</pre>
<p>I created a new notebook and started like part 1 with reading the data and naming the first column</p>
<pre>import pandas as pd

df = pd.read_csv("./aoc_day_01_data.txt", header=None)
df.columns = ["original"]</pre>
<p>To add the sum of three values to the row of the first value we use the following code</p>
<pre>indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=3)
df["rolling_sum"] = df.original.rolling(window=indexer).sum()</pre>
<p>This demonstrates the power of Pandas once more: you have integrated sliding window functions!</p>
<p>The rest is equal to part one &#8220;shift, compare and count&#8221;</p>
<pre>df['shifted_rs'] = df['rolling_sum'].shift(-1)
df['increased_rs'] = (df['shifted_rs'] &gt; df['rolling_sum'])
true_count = df['increased_rs'].sum()
true_count</pre>
<p>As a little Fingerübung I did the same with vanilla Python:</p>
<pre>data = []
with open("./aoc_day_01_test_data.txt") as f:
    for line in f:
        data.append(int(line.rstrip()))

triplet_sums = []

for i, v in enumerate(data):
    if i &lt; (len(data) - 2):
        triplet_sum = data[i] + data[i+1] + data[i+2]
        triplet_sums.append(triplet_sum)
print(triplet_sums)

sums_larger_than_previous_sums = 0
for i, v in enumerate(triplet_sums):
    if i &lt; (len(triplet_sums) - 1):
        if triplet_sums[i] &lt; triplet_sums[i+1]:
            sums_larger_than_previous_sums += 1

print(sums_larger_than_previous_sums)</pre>
<p>Which works but is less elegant.</p>
<p>Stay tuned for more!</p>
<p>The post <a href="https://creatronix.de/2021-advent-of-code-day-1/">2021 &#8211; Advent of code &#8211; Day 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to visualize geo coordinates with ipyleaflet</title>
		<link>https://creatronix.de/visualize-geo-coordinates-with-ipyleaflet/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 18 Nov 2021 12:10:47 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[geo coordinates]]></category>
		<category><![CDATA[ipyleaflet]]></category>
		<category><![CDATA[jupyter]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=4126</guid>

					<description><![CDATA[<p>As mentioned in Curriculum Vitae for Data Scientists it can be a good idea to visualize your skills and work experience. I&#8217;ve also tried to visualize the location of my work places with geopandas but I came across a more fancy solution called ipyleaflet Installation pip install ipyleaflet Visualizing geo coordinates from ipyleaflet import Map,&#8230;</p>
<p>The post <a href="https://creatronix.de/visualize-geo-coordinates-with-ipyleaflet/">How to visualize geo coordinates with ipyleaflet</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As mentioned in <a href="https://creatronix.de/curriculum-vitae-for-data-scientists/">Curriculum Vitae for Data Scientists</a> it can be a good idea to visualize your skills and work experience. I&#8217;ve also tried to visualize the location of my work places with geopandas but I came across a more fancy solution called <a href="https://ipyleaflet.readthedocs.io/en/latest/">ipyleaflet</a><span id="more-4126"></span></p>
<h2>Installation</h2>
<pre>pip install ipyleaflet</pre>
<h2>Visualizing geo coordinates</h2>
<pre>from ipyleaflet import Map, Marker, basemaps, basemap_to_tiles

m = Map(
    basemap=basemaps.OpenStreetMap.Mapnik,
    center=(52, 8),
    zoom=5
)
cities = {  "Bad Oeynhausen":
              { "latitude":52.207851, "longitude":8.804030},
            "Detmold":
              { "latitude":51.936284, "longitude":8.879153},
            "Coburg":
              { "latitude":50.258112, "longitude":10.964463},
            "Bochum":
              { "latitude":51.481811, "longitude":7.219664},
            "Karlsbad":
               { "latitude":48.881417, "longitude":8.507199},
            "Nürnberg":
               { "latitude":49.447537, "longitude":11.102352},
             "Erlangen - Tennenlohe":
               { "latitude":49.547055, "longitude":11.015774}
          }

for city, coordinates in cities.items():

    m.add_layer(Marker(location=(coordinates["latitude"], coordinates["longitude"])))

m</pre>
<p>The result:</p>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-4133 size-full" src="https://creatronix.de/wp-content/uploads/2021/11/ipyleaflet_map.png" alt="" width="995" height="417" srcset="https://creatronix.de/wp-content/uploads/2021/11/ipyleaflet_map.png 995w, https://creatronix.de/wp-content/uploads/2021/11/ipyleaflet_map-300x126.png 300w, https://creatronix.de/wp-content/uploads/2021/11/ipyleaflet_map-768x322.png 768w" sizes="(max-width: 995px) 100vw, 995px" /></p>
<p>The post <a href="https://creatronix.de/visualize-geo-coordinates-with-ipyleaflet/">How to visualize geo coordinates with ipyleaflet</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Introduction to Jupyter Notebook</title>
		<link>https://creatronix.de/introduction-to-jupyter-notebook/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Wed, 25 Apr 2018 09:17:48 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[data science]]></category>
		<category><![CDATA[jupyter]]></category>
		<category><![CDATA[notebook]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1214</guid>

					<description><![CDATA[<p>JuPyteR Do You know the feeling of being already late to a party when encountering something new? But when you actually start telling others about it, you realize that it is not too common knowledge at all, e.g. Jupyter Notebooks. What is a Jupyter notebook? In my own words: a browser-based document-oriented command line style&#8230;</p>
<p>The post <a href="https://creatronix.de/introduction-to-jupyter-notebook/">Introduction to Jupyter Notebook</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>JuPyteR</h2>
<h2><img decoding="async" class="wp-image-2253 size-full" src="https://creatronix.de/wp-content/uploads/2018/10/img_5986.jpg" width="500" height="627" srcset="https://creatronix.de/wp-content/uploads/2018/10/img_5986.jpg 500w, https://creatronix.de/wp-content/uploads/2018/10/img_5986-239x300.jpg 239w" sizes="(max-width: 500px) 100vw, 500px" /></h2>
<p>Do You know the feeling of being already late to a party when encountering something new?</p>
<p>But when you actually start telling others about it, you realize that it is not too common knowledge at all, e.g. <a href="http://jupyter.org/">Jupyter Notebooks</a>.</p>
<p>What is a Jupyter notebook?</p>
<p>In my own words: a browser-based document-oriented command line style exploration tool for <strong>Ju</strong>lia, <strong>Py</strong>thon and <strong>R</strong>, hence the name JuPyteR Huh!</p>
<p>Ok, let&#8217;s break it down:</p>
<h3>Browser-based</h3>
<p>JuPyter is a client-server concept where you edit your code in a web form in a browser. You send the input of a cell to the server backend for execution and the server sends back a response which will be rendered in your browser.</p>
<h3><img decoding="async" src="https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter-1024x402.png" alt="" class="alignnone size-large wp-image-5952" width="1024" height="402" srcset="https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter-1024x402.png 1024w, https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter-300x118.png 300w, https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter-768x302.png 768w, https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter-1536x603.png 1536w, https://creatronix.de/wp-content/uploads/2018/04/iris_jupyter.png 1858w" sizes="(max-width: 1024px) 100vw, 1024px" /></h3>
<h3>Document-oriented</h3>
<p>On great aspect of a JuPyter is that You can enrich your code in a nice fashion with headlines and markdown code so that you have a document containing code, the result of the code execution and documentation.</p>
<p><a href="http://jupyter.org/"><img decoding="async" src="https://creatronix.de/wp-content/uploads/2018/04/markdown_jupyter-1024x780.png" alt="" class="alignnone size-large wp-image-5965" width="1024" height="780" srcset="https://creatronix.de/wp-content/uploads/2018/04/markdown_jupyter-1024x780.png 1024w, https://creatronix.de/wp-content/uploads/2018/04/markdown_jupyter-300x229.png 300w, https://creatronix.de/wp-content/uploads/2018/04/markdown_jupyter-768x585.png 768w, https://creatronix.de/wp-content/uploads/2018/04/markdown_jupyter.png 1482w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h2>Installation and Run</h2>
<p>If You already have a python installation You can either use pip or pipenv to install JuPyter</p>
<h3>Pip</h3>
<pre>pip install jupyter</pre>
<h3>Pipenv</h3>
<pre>pipenv install jupyter</pre>
<p>After installation you can start it on the console with:</p>
<pre>jupyter notebook</pre>
<p>An alternative way is to use the <a href="https://www.anaconda.com/download/">anaconda distribution</a>.</p>
<h2>Disadvantages</h2>
<p>On big drawback -when your background is SW development- is that You don&#8217;t have code completion.<strong></strong></p>
<p>Another disadvantage: modularization of your code is not easy.</p>
<p>Versioning is an issue as well. Because the Jupyter notebook&#8217;s json files contains code and generated artifacts like plots every re-run of a notebook changes the file. The diff is not easily comprehensible.</p>
<h2>PyCharm Integration</h2>
<p>For the code completion issue there is JetBrains for the rescue: PyCharm IDE has an integrated JuPyter editor which supports code completion.</p>
<h2><img decoding="async" src="https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-1024x351.png" alt="" class="alignnone size-large wp-image-5967" width="1024" height="351" srcset="https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-1024x351.png 1024w, https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-300x103.png 300w, https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-768x263.png 768w, https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-1536x526.png 1536w, https://creatronix.de/wp-content/uploads/2018/04/pycharm_jupyter-2048x701.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></h2>
<h2>Useful Keyboard Shortcuts</h2>
<p>You can open command palette via</p>
<p>Cmd + Shift + P on Mac OS or via</p>
<p>Ctrl + Shift + P on Linux and Windows</p>
<p>Ctrl + Enter Run Cell</p>
<p>Alt + Enter Run Cell and insert new cell below</p>
<p><a href="https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/">https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/</a></p>
<p>The post <a href="https://creatronix.de/introduction-to-jupyter-notebook/">Introduction to Jupyter Notebook</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
