Reputation: 55
I have a dataframe called "time_df" which has one column "tstamps" which is consists of string values.I need to add a "0" to row 0,5,10,.... till the end of the dataframe.
Is there a function/method to accomplish this? Thanks.
Upvotes: 1
Views: 33
Reputation: 34056
Use Series.str.ljust
:
Consider below df
:
In [1883]: df = pd.DataFrame({'tstamps':['1606.9104', '1606.91046', '1606.9107']})
In [1884]: df
Out[1884]:
tstamps
0 1606.9104
1 1606.91046
2 1606.9107
Now, you have to make all rows length
to 10
by adding 0
to the right wherever missing.
In [1889]: df['tstamps'] = df['tstamps'].str.ljust(10, '0')
In [1890]: df
Out[1890]:
tstamps
0 1606.91040
1 1606.91046
2 1606.91070
Upvotes: 1