Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert python list to Pandas series

Tags:

python

pandas

I have a python list l.The first few elements of the list looks like below

[751883787]
[751026090]
[752575831]
[751031278]
[751032392]
[751027358]
[751052118]

I want to convert this list to pandas.core.series.Series with 2 leading 0.My final outcome will look like

00751883787
00751026090
00752575831
00751031278
00751032392
00751027358
00751052118

I'm working in Python 3.x in windows environment.Can you suggest me how to do this? Also my list contains around 2000000 elements

like image 752
Christina Hughes Avatar asked Dec 05 '22 12:12

Christina Hughes


1 Answers

you can try:

list=[121,123,125,145]
series='00'+pd.Series(list).astype(str)
print(series)

output:

0    00121
1    00123
2    00125
3    00145
dtype: object
like image 152
riccardo nizzolo Avatar answered Dec 08 '22 01:12

riccardo nizzolo