<p dir="auto">The shift method in SparseDataFrame does not respond to axis correctly.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; df = pd.SparseDataFrame(np.random.rand(10,5))
&gt;&gt;&gt; df.shift(1)
          0         1         2         3         4
0       NaN       NaN       NaN       NaN       NaN
1  0.015673  0.456047  0.451249  0.297851  0.178720
2  0.393355  0.594275  0.496614  0.936675  0.311961
3  0.255445  0.141111  0.750324  0.994727  0.965763
4  0.473577  0.644481  0.584495  0.796462  0.689525
5  0.744432  0.918232  0.715706  0.672892  0.598817
6  0.732707  0.110259  0.756422  0.534970  0.449421
7  0.340564  0.907769  0.543032  0.214241  0.564122
8  0.291026  0.616647  0.102853  0.940241  0.693239
9  0.445545  0.760656  0.035569  0.398808  0.050392

[10 rows x 5 columns]
&gt;&gt;&gt; df.shift(1,axis=1)
          0         1         2         3         4
0       NaN       NaN       NaN       NaN       NaN
1  0.015673  0.456047  0.451249  0.297851  0.178720
2  0.393355  0.594275  0.496614  0.936675  0.311961
3  0.255445  0.141111  0.750324  0.994727  0.965763
4  0.473577  0.644481  0.584495  0.796462  0.689525
5  0.744432  0.918232  0.715706  0.672892  0.598817
6  0.732707  0.110259  0.756422  0.534970  0.449421
7  0.340564  0.907769  0.543032  0.214241  0.564122
8  0.291026  0.616647  0.102853  0.940241  0.693239
9  0.445545  0.760656  0.035569  0.398808  0.050392

[10 rows x 5 columns]
&gt;&gt;&gt;"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; df = pd.SparseDataFrame(np.random.rand(10,5))
&gt;&gt;&gt; df.shift(1)
          0         1         2         3         4
0       NaN       NaN       NaN       NaN       NaN
1  0.015673  0.456047  0.451249  0.297851  0.178720
2  0.393355  0.594275  0.496614  0.936675  0.311961
3  0.255445  0.141111  0.750324  0.994727  0.965763
4  0.473577  0.644481  0.584495  0.796462  0.689525
5  0.744432  0.918232  0.715706  0.672892  0.598817
6  0.732707  0.110259  0.756422  0.534970  0.449421
7  0.340564  0.907769  0.543032  0.214241  0.564122
8  0.291026  0.616647  0.102853  0.940241  0.693239
9  0.445545  0.760656  0.035569  0.398808  0.050392

[10 rows x 5 columns]
&gt;&gt;&gt; df.shift(1,axis=1)
          0         1         2         3         4
0       NaN       NaN       NaN       NaN       NaN
1  0.015673  0.456047  0.451249  0.297851  0.178720
2  0.393355  0.594275  0.496614  0.936675  0.311961
3  0.255445  0.141111  0.750324  0.994727  0.965763
4  0.473577  0.644481  0.584495  0.796462  0.689525
5  0.744432  0.918232  0.715706  0.672892  0.598817
6  0.732707  0.110259  0.756422  0.534970  0.449421
7  0.340564  0.907769  0.543032  0.214241  0.564122
8  0.291026  0.616647  0.102853  0.940241  0.693239
9  0.445545  0.760656  0.035569  0.398808  0.050392

[10 rows x 5 columns]
&gt;&gt;&gt;
</code></pre></div>
<p dir="auto">Using Pandas version 0.13.1</p>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-text-roff notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import pandas as pd
import StringIO

# Store the csv string in a variable 
gps_string = &quot;&quot;&quot;
&quot;2010-01-12 18:00:00&quot;,&quot;$GPGGA&quot;,&quot;180439&quot;,&quot;7249.2150&quot;,&quot;N&quot;,&quot;11754.4238&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.9&quot;,&quot;-8.1&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*57&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 17:30:00&quot;,&quot;$GPGGA&quot;,&quot;173439&quot;,&quot;7249.2160&quot;,&quot;N&quot;,&quot;11754.4233&quot;,&quot;W&quot;,&quot;2&quot;,&quot;11&quot;,&quot;0.8&quot;,&quot;-4.5&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*5B&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 17:00:00&quot;,&quot;$GPGGA&quot;,&quot;170439&quot;,&quot;7249.2152&quot;,&quot;N&quot;,&quot;11754.4235&quot;,&quot;W&quot;,&quot;2&quot;,&quot;11&quot;,&quot;0.8&quot;,&quot;-3.1&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*5C&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 16:30:00&quot;,&quot;N&quot;,&quot;11754.4210&quot;,&quot;W&quot;,&quot;2&quot;,&quot;09&quot;,&quot;1.1&quot;,&quot;-13.1&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*6C&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 16:00:00&quot;,&quot;N&quot;,&quot;11754.4229&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.9&quot;,&quot;-2.9&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*53&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 15:30:00&quot;,&quot;N&quot;,&quot;11754.4269&quot;,&quot;W&quot;,&quot;2&quot;,&quot;09&quot;,&quot;0.8&quot;,&quot;-4.3&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*54&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 15:00:00&quot;,&quot;N&quot;,&quot;11754.4267&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.8&quot;,&quot;-1.6&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*56&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 14:30:00&quot;,&quot;$GPGGA&quot;,&quot;143439&quot;,&quot;7249.2152&quot;,&quot;N&quot;,&quot;11754.4253&quot;,&quot;W&quot;,&quot;2&quot;,&quot;11&quot;,&quot;0.7&quot;,&quot;-4.3&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*56&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 14:00:00&quot;,&quot;N&quot;,&quot;11754.4245&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.9&quot;,&quot;-7.0&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*50&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 13:30:00&quot;,&quot;$GPGGA&quot;,&quot;133439&quot;,&quot;7249.2134&quot;,&quot;N&quot;,&quot;11754.4243&quot;,&quot;W&quot;,&quot;2&quot;,&quot;11&quot;,&quot;0.7&quot;,&quot;-10.7&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*61&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 13:00:00&quot;,&quot;N&quot;,&quot;11754.4245&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.8&quot;,&quot;-5.5&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*56&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 12:30:00&quot;,&quot;N&quot;,&quot;11754.4226&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.9&quot;,&quot;-7.1&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*59&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 12:00:00&quot;,&quot;N&quot;,&quot;11754.4238&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.8&quot;,&quot;-6.5&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*51&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 11:30:00&quot;,&quot;N&quot;,&quot;11754.4227&quot;,&quot;W&quot;,&quot;2&quot;,&quot;10&quot;,&quot;0.8&quot;,&quot;0.1&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*73&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 11:00:00&quot;,&quot;-7.4&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*5F&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;
&quot;2010-01-12 10:30:00&quot;,&quot;N&quot;,&quot;11754.4271&quot;,&quot;W&quot;,&quot;2&quot;,&quot;08&quot;,&quot;1.1&quot;,&quot;-8.4&quot;,&quot;M&quot;,&quot;-12.4&quot;,&quot;M&quot;,&quot;&quot;,&quot;*5A&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot; &quot;&quot;&quot;

# Read the csv string into a dataframe.
gps_df = pd.read_csv(StringIO.StringIO(gps_string), header=None, index_col=0)
rows_to_shift = gps_df[gps_df[15].isnull()].index
gps_df.loc[rows_to_shift] = gps_df.loc[rows_to_shift].shift(periods=1, axis=1)
# create this file to see the outcome
gps_df.to_csv(&quot;f.csv&quot;) "><pre class="notranslate">import pandas as pd
import StringIO

# Store the csv string in a variable 
gps_string = """
"2010-01-12 18:00:00","$GPGGA","180439","7249.2150","N","11754.4238","W","2","10","0.9","-8.1","M","-12.4","M","","*57","","",""
"2010-01-12 17:30:00","$GPGGA","173439","7249.2160","N","11754.4233","W","2","11","0.8","-4.5","M","-12.4","M","","*5B","","",""
"2010-01-12 17:00:00","$GPGGA","170439","7249.2152","N","11754.4235","W","2","11","0.8","-3.1","M","-12.4","M","","*5C","","",""
"2010-01-12 16:30:00","N","11754.4210","W","2","09","1.1","-13.1","M","-12.4","M","","*6C","","","","","",""
"2010-01-12 16:00:00","N","11754.4229","W","2","10","0.9","-2.9","M","-12.4","M","","*53","","","","","",""
"2010-01-12 15:30:00","N","11754.4269","W","2","09","0.8","-4.3","M","-12.4","M","","*54","","","","","",""
"2010-01-12 15:00:00","N","11754.4267","W","2","10","0.8","-1.6","M","-12.4","M","","*56","","","","","",""
"2010-01-12 14:30:00","$GPGGA","143439","7249.2152","N","11754.4253","W","2","11","0.7","-4.3","M","-12.4","M","","*56","","",""
"2010-01-12 14:00:00","N","11754.4245","W","2","10","0.9","-7.0","M","-12.4","M","","*50","","","","","",""
"2010-01-12 13:30:00","$GPGGA","133439","7249.2134","N","11754.4243","W","2","11","0.7","-10.7","M","-12.4","M","","*61","","",""
"2010-01-12 13:00:00","N","11754.4245","W","2","10","0.8","-5.5","M","-12.4","M","","*56","","","","","",""
"2010-01-12 12:30:00","N","11754.4226","W","2","10","0.9","-7.1","M","-12.4","M","","*59","","","","","",""
"2010-01-12 12:00:00","N","11754.4238","W","2","10","0.8","-6.5","M","-12.4","M","","*51","","","","","",""
"2010-01-12 11:30:00","N","11754.4227","W","2","10","0.8","0.1","M","-12.4","M","","*73","","","","","",""
"2010-01-12 11:00:00","-7.4","M","-12.4","M","","*5F","","","","","","","","","","","",""
"2010-01-12 10:30:00","N","11754.4271","W","2","08","1.1","-8.4","M","-12.4","M","","*5A","","","","","","" """

# Read the csv string into a dataframe.
gps_df = pd.read_csv(StringIO.StringIO(gps_string), header=None, index_col=0)
rows_to_shift = gps_df[gps_df[15].isnull()].index
gps_df.loc[rows_to_shift] = gps_df.loc[rows_to_shift].shift(periods=1, axis=1)
# create this file to see the outcome
gps_df.to_csv("f.csv") </pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I am trying to use the <code class="notranslate">Dataframe. shift()</code>  function to move certain rows of data into their correct columns, and the <code class="notranslate">Dataframe.shift()</code> function is doing some weird things, it is creating an empty column of <code class="notranslate">null(s)</code> and moves one of the columns to the end of the <code class="notranslate">dataframe</code>.</p>
<p dir="auto"><strong>Screenshots</strong></p>
<p dir="auto">Original data:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24297785/59721139-3c332080-91e6-11e9-9468-fc876234ecaa.png"><img width="1268" alt="Screen Shot 2019-06-18 at 4 09 22 PM" src="https://user-images.githubusercontent.com/24297785/59721139-3c332080-91e6-11e9-9468-fc876234ecaa.png" style="max-width: 100%;"></a></p>
<p dir="auto">Output after execution of the code</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24297785/59721303-9d5af400-91e6-11e9-9cdb-6988a32e9720.png"><img width="1250" alt="Screen Shot 2019-06-18 at 4 31 15 PM" src="https://user-images.githubusercontent.com/24297785/59721303-9d5af400-91e6-11e9-9cdb-6988a32e9720.png" style="max-width: 100%;"></a></p>
<p dir="auto">As seen above, the data that was originally in column 10  has been move to column 15  for some reason. Also a column with <code class="notranslate">null</code> values has been created in column 6.</p>
<p dir="auto">I expect that the data should be moved to the right by one step, that is the data in each column should move to the column to the left of it, and the current behaviour is confusing, based on the documentation of what this function should do.</p>
<p dir="auto">My expected output:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24297785/59721366-ced3bf80-91e6-11e9-9330-7889d4afffc2.png"><img width="1227" alt="Screen Shot 2019-06-18 at 4 16 40 PM" src="https://user-images.githubusercontent.com/24297785/59721366-ced3bf80-91e6-11e9-9330-7889d4afffc2.png" style="max-width: 100%;"></a></p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 2.7.14.final.0<br>
python-bits: 32<br>
OS: Windows</p>
</details>