I have a dataframe that looks like this:
x frames
0 7729.00
0 7730.00
0 7731.00
1 7735.00
1 7736.00
1 7737.00
1 7738.00
2 7741.00
2 7742.00
As you can see, the value for frames is sequential, but when x changes, there is a jump in frames. I want to continue frames so that it always increases by 1 and in this case, make x nan. Like this:
x frames
0 7729.00
0 7730.00
0 7731.00
Nan 7732.00
Nan 7733.00
Nan 7734.00
1 7735.00
1 7736.00
1 7737.00
1 7738.00
Nan 7739.00
Nan 7740.00
2 7741.00
2 7742.00
EDIT
Here is the error I get using the first solution.
df = df.set_index('frames').reindex(range(s.min(), s.max() + 1)).reset_index()
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/util/_decorators.py", line 227, in wrapper
return func(*args, **kwargs)
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py", line 3856, in reindex
return super().reindex(**kwargs)
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 4544, in reindex
axes, level, limit, tolerance, method, fill_value, copy
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py", line 3744, in _reindex_axes
index, method, copy, level, fill_value, limit, tolerance
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py", line 3766, in _reindex_index
allow_dups=False,
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 4613, in _reindex_with_indexers
copy=copy,
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 1251, in reindex_indexer
self.axes[axis]._can_reindex(indexer)
File "/Users/asi/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3099, in _can_reindex
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis
If I have another column in the dataframe, like this:
x y frames
0 yes 7729.00
0 yes 7730.00
0 yes 7731.00
1 no 7735.00
1 no 7736.00
1 no 7737.00
1 no 7738.00
2 yes 7741.00
2 yes 7742.00
Then the solution turns all other columns (x and y) to NaN.