<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style id="ms-outlook-ios-style" type="text/css">html {
background-color: transparent;
}

body {
color: #333;
line-height: 150%;
font-family: "-apple-system", "HelveticaNeue";
margin: 0;
}

.ms-outlook-ios-reference-expand {
display: block;
color: #999;
padding: 20px 0px;
text-decoration: none;
}

.ms-outlook-ios-availability-container {
max-width: 500px;
margin: auto;
padding: 12px 15px 15px 15px;
border: 1px solid #C7E0F4;
border-radius: 4px;
}

.ms-outlook-ios-availability-container > .ms-outlook-ios-availability-delete-button {
width: 25px;
height: 25px;
right: -12px;
top: -12px;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAYAAAA4TnrqAAAAAXNSR0IArs4c6QAACxpJREFUeAHlnFuMXlUVx/fcOzNtp0ynF0U7hWKrEmKLosZEjUZ9MgZIQBNC0uAtJr745oOJIT74xgskJkQbAlQNJmBMfNDEG0YjEC7GIBQZ6IAI005L79O5+/+dfut0f5dzzt7nu8w37UrWt893zt5rr/U/e6+zL+ucHrcGtLq62q9qd4gnxTeKb6kcc267eEI8Kz4mnhFPi58Rv1g5nunp6VnS8ZVHAqdHPCk+KP6zuBWEHORNinvWNWoYIN4q/o74mLidhHzqob71AxzKij8g/p14LYh6qb97QUM58T7x38TdQOiBPt0FmhQaEf9M3I2EXiNr7tOkBK3pVvGCuJsJ/dCzqVbWWxZxVTygso+InxBz3M2Efuj5SEXvUrqWQloV7lRtT4vfX6rWtS30pqr/uMZp78SqEQ2WgPqQKvmnuKWtaWnFuaWVVbciXl51rk+a9fb2uP6EY80qzL+oHB8RYC8V5vQyRIEloD6tsk965UsdAsyZ+WV35uKyOz+/4uZ0YgmEMqhfyA3397rRoV63eUOf2zzUJxAzMsed/owA+2tokWCwmgVKDcadvLDsZs8vutMXV5zkhepYl08GurENvW5idMCNj/Q5Nb5mKBiwoGoqXe/fZTQCkmNnl9x/Ty+4xZzW0yeLB9WC6Hp0QbLSJRd0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6Ov040O3J06LsV3CKzVpBvqgClPUJQfUcEWO8Dgjoi79UDoaYNp9MeOQPohQJHXfBbHD/NTRDRFooKN2IeLiEyxYh1N0e9t6WmE/hFu4DEr54P1B50MGs2z4E9UMMS0gdDE5eYG9YmsdvygF/rZxBm9/Q2Lgjp/r+vp4zYFS00Nc39cUDi9TPi0TUDZ4X1FCnUjoZfFZqAvekfQd60LUiYFqyLgUaXTlePchMgUwqclLMl3WvtvhCZ2E6EPekHoib4RET9/V7FXk8KVnyqwJJBByI/8DHnHbCkRPm2E/+oWwGpjStHT3wIznXPSe/xWRb4qsCoFDyl9qnJcmBBnTvi0EYC9NLN2PgwfRf3oYYR+kfHwYFDnvxs+FDRIPaDMfHQiaJbJc7U2vJvH85UWB98QLNnOqP4+Jd/jOJTW+g0Lhgf21MNHdeQNC8ARWAymcHIf5X8osVZ01b27AzgC7Holz4nH+B9KDAKvqrfCDBgB9hUdPy4O8l9WjpRFtqvmfUMzXIB9U8cP2v+YFOcf8yYr227sTLHCwexgXb3JasAIsB/oOHgMZuUsxXha2hX/jrQZ3CxgJoe1LSLuCCSLfvteczuWuANXOK3KrDT4ZXIEZA4dsqRXuuRPdD3ah2XJ5DwAEs1C16MV0hXpksznWgSMXz0j1vZ+18FqE2A4/YfFUU9JK7/G6Zuqv9QXQxpNdwpt0YDvN8p0szhoZ6hQYOcyHFZVvDSe+5Z9W9RRCxsU3ydeEnczteQrRy0BUSgdEP+jS9Hqju9n+UgLKL6l9XXx0S4BrTu/zFYDWr/AOig+skagdf83/3zAOBZQvOryRTEf+Donbid15GuS0eOsWlBC/gsl9iW/LP6C+PPi68TN0usS8EcxH6z4be2qZrPCG5XvCFi1FQu8SZ1j6YdXYeC9YuLxiZyGicQltpuoRPiEmJVLwqPgZwXOtNKO0v8BzRAPSFNM7HEAAAAASUVORK5CYII=");
background-size: 25px 25px;
background-position: center;
}

#ms-outlook-ios-main-container {
margin: 0 0 0 0;
margin-top: 120;
padding: 8;
}

#ms-outlook-ios-content-container {
padding: 0;
padding-top: 12;
padding-bottom: 20;
}

.ms-outlook-ios-mention {
color: #333;
background-color: #f1f1f1;
border-radius: 4px;
padding: 0 2px 0 2px;
pointer-events: none;
text-decoration: none;
}

.ms-outlook-ios-mention-external {
color: #ba8f0d;
background-color: #fdf7e7;
}

.ms-outlook-ios-mention-external-clear-design {
color: #ba8f0d;
background-color: #f1f1f1;
}</style>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
<div style="direction: ltr;">
<div>
<div>
<div style="direction:ltr">Thanks a lot, Thomas.</div>
<div><br>
</div>
<div style="direction:ltr">I donít have index when I read in the data. I just want to slice two series to the same length, and subtract. Thatís it!</div>
<div style="direction:ltr"><br>
</div>
<div style="direction:ltr">I also donít what numpy methods wrapped within methods. They work, but hard do understand.</div>
<div style="direction:ltr"><br>
</div>
<div style="direction:ltr">How would you do it? In Matlab or R, itís very simple, one line.</div>
<div><br>
</div>
<div style="direction:ltr"><br>
</div>
</div>
<div><br>
</div>
<div class="ms-outlook-ios-signature"></div>
</div>
<div> </div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="dir="ltr""><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> SciPy-User <scipy-user-bounces+tmrsg11=gmail.com@python.org> on behalf of Thomas Kluyver <takowl@gmail.com><br>
<b>Sent:</b> Thursday, February 14, 2019 4:54 PM<br>
<b>To:</b> SciPy Users List<br>
<b>Cc:</b> Discussion of Numerical Python<br>
<b>Subject:</b> Re: [SciPy-User] [Numpy-discussion] Why slicing Pandas column and then subtract gives NaN?
<div> </div>
</font></div>
<meta content="text/html; charset=utf-8">
<div dir="ltr">
<div>Maybe it's useful to look a bit more at what pandas is doing and why. The 'index' on a series or dataframe labels each row - e.g. if your series is measuring total sales for each day, its index would be the dates. When you combine (e.g. subtract) two series,
 pandas automatically lines up the indices. So it will join up the numbers for February 14th, even if they're not in the same position in the data.</div>
<div><br>
</div>
<div>In your example, you haven't specified an index, so pandas generates an integer index which doesn't really mean anything, and aligning on it doesn't do what you want.</div>
<div><br>
</div>
<div>What are you trying to do? If Numpy does exactly what you want, then the answer might be to use Numpy.</div>
<div><br>
</div>
<div>> Isn't Numpy built on top of Pandas?</div>
<div><br>
</div>
<div>It's the other way round: pandas is built on Numpy. Pandas indices are an extra layer of functionality on top of what Numpy does.<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, 14 Feb 2019 at 20:22, C W <<a href="mailto:tmrsg11@gmail.com">tmrsg11@gmail.com</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">Hi Paul,
<div><br>
</div>
<div>Thanks for your response! I did not find a Pandas list for users, only for developers. I'd love to be on there.</div>
<div><br>
</div>
<div>
<pre style="white-space:pre-wrap">result = a.subtract(b.shift()).dropna()</pre>
</div>
<div>This seems verbose, several layers of parenthesis follow by a dot method. I'm new to Python, I thought Python code would be pity and short. Is this what everyone will write?</div>
<div><br>
</div>
<div>Thank you!</div>
<div>
<pre style="white-space:pre-wrap"><br></pre>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Feb 13, 2019 at 6:50 PM Paul Hobson <<a href="mailto:pmhobson@gmail.com" target="_blank">pmhobson@gmail.com</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div>This is more a question for the pandas list, but since i'm here i'll take a crack.</div>
<div><br>
</div>
<ul>
<li>numpy aligns arrays by position. </li><li>pandas aligns by label.</li></ul>
<div>So what you did in pandas is roughly equivalent to the following:</div>
<div><br>
</div>
<div><span style="font-family:monospace,monospace">a = pandas.Series([85, 86, 87, 86], name='a').iloc[1:4].to_frame()<br>
b = pandas.Series([15, 72, 2, 3], name='b').iloc[0:3].to_frame()<br>
result = a.join(b,how='outer').assign(diff=lambda df: df['a'] - df['b'])</span></div>
<div><span style="font-family:monospace,monospace">print(result)</span></div>
<div>
<div class="gmail-m_2555636644403782788gmail-m_844511772299979860gmail-m_-2112474692217377193gmail-output_subarea gmail-m_2555636644403782788gmail-m_844511772299979860gmail-m_-2112474692217377193gmail-output_text gmail-m_2555636644403782788gmail-m_844511772299979860gmail-m_-2112474692217377193gmail-output_stream gmail-m_2555636644403782788gmail-m_844511772299979860gmail-m_-2112474692217377193gmail-output_stdout">
<pre>      a     b  diff
0   NaN  15.0   NaN
1  86.0  72.0  14.0
2  87.0   2.0  85.0
3  86.0   NaN   NaN<br><br>
<span style="font-family:arial,helvetica,sans-serif">So what I think you want would be the following:</span>

</pre>
<pre>a = pandas.Series([85, 86, 87, 86], name='a')<br>b = pandas.Series([15, 72, 2, 3], name='b')<br>result = a.subtract(b.shift()).dropna()<br>print(result)<br>1    71.0
2    15.0
3    84.0
dtype: float64

</pre>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Feb 13, 2019 at 2:51 PM C W <<a href="mailto:tmrsg11@gmail.com" target="_blank">tmrsg11@gmail.com</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Dear list,
<div><br>
</div>
<div>I have the following to Pandas Series: a, b. I want to slice and then subtract. Like this: a[1:4] - b[0:3]. Why does it give me NaN? But it works in Numpy.</div>
<div>
<div style="line-height:23px">
<div style="color:rgb(0,0,0); font-family:Menlo,Monaco,"Courier New",monospace; font-size:15px; white-space:pre-wrap">
<br>
</div>
<div style="white-space:pre-wrap">Example 1: did not work</div>
<div style="color:rgb(0,0,0); font-family:Menlo,Monaco,"Courier New",monospace; font-size:15px; white-space:pre-wrap">
<span style="font-family:Arial,Helvetica,sans-serif; font-size:small; color:rgb(34,34,34)">>>>a = pd.Series([85, 86, 87, 86])</span><br>
</div>
</div>
<div style="line-height:23px">>>>b = pd.Series([15, 72, 2, 3])
<div>>>> a[1:4]-b[0:3]<font face="Menlo, Monaco, Courier New, monospace" color="#000000"><span style="font-size:15px; white-space:pre-wrap">
</span></font>0   NaN<font face="Menlo, Monaco, Courier New, monospace" color="#000000"><span style="font-size:15px; white-space:pre-wrap">
</span></font>1   14.0<font face="Menlo, Monaco, Courier New, monospace" color="#000000"><span style="font-size:15px; white-space:pre-wrap">
</span></font>2   85.0<font face="Menlo, Monaco, Courier New, monospace" color="#000000"><span style="font-size:15px; white-space:pre-wrap">
</span></font>3   NaN<br>
</div>
<div>
<div>>>> type(a[1:4])</div>
<div><class 'pandas.core.series.Series'></div>
<div><br>
</div>
</div>
<div>Example 2: worked</div>
</div>
</div>
<div style="line-height:23px">If I use values() method, it's converted to a Numpy object. And it works!</div>
<div style="line-height:23px">
<div style="line-height:23px">>>> a.values[1:4]-b.values[0:3]</div>
<div style="line-height:23px">array([71, 15, 84])</div>
<div style="line-height:23px">
<div>>>> type(a.values[1:4])</div>
<div><class 'numpy.ndarray'></div>
<br class="gmail-m_2555636644403782788gmail-m_844511772299979860gmail-m_-2112474692217377193gmail-m_-8744438713277675593gmail-Apple-interchange-newline">
</div>
<div style="line-height:23px">What's the reason that Pandas in example 1 did not work? Isn't Numpy built on top of Pandas? So, why is everything ok in Numpy, but not in Pandas?</div>
<div style="line-height:23px"><br>
</div>
<div style="line-height:23px">Thanks in advance!</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote>
</div>
_______________________________________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org" target="_blank">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scipy-user</a><br>
</blockquote>
</div>
_______________________________________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org" target="_blank">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scipy-user</a><br>
</blockquote>
</div>
</div>
</body>
</html>