I have a data-frame (df) with a column called Id which looks like
Id
0 3
1 67
2 356
3
:
50 P4
51 P5
52 678
53
54 2
The column has a type: dtype: object
I have worked out the maximum Id value and assigned to a variable called maxId (which is 678 and am looking to apply a sequentially increasing maxId to the empty elements so in this example my output would be:
Id
0 3
1 67
2 356
3 679
:
50 P4
51 P5
52 678
53 680
54 2
Where element 3 and 53 are assigned values of 679 and 680 respectively.
I have tried the following code where i loop through the column looking for null elements and then applythuing the maxId to these:
for item, frame in df['Id'].iteritems():
if pd.isnull(frame):
maxId = maxId + 1
frame['Id'] = maxId
But I get an error:
TypeError: 'float' object is not subscriptable
What do I need to do for a fix?
forloops. Vectorised column-wise operations are possible.