How to retain leading 0's when converting xml to csv

60 Views Asked by At

I have this code, in the XML page the DateTime is 01052022000000000, but when it comes to python it appears like 1052022000000000 (the left zero was deleted).

I try to use ( apply('{:0>17}'.format) ) but nothing happen.

any help?

import pandas as pd
import pandas as pd

url = (
    "http://90.161.233.78:65518/services/user/records.xml?"
    "begin=01052022?end=01052022?"
    "var=EDSLINEEMBEDDED.Module2.AE1?var=EDSLINEEMBEDDED.Module2.VI1?period=900")

df = pd.read_xml(url, xpath="//record/* | //dateTime") 
df["dateTime"] = df["dateTime"].ffill()
print(df["dateTime"])
df['dateTime']=df['dateTime'].apply('{:0>17}'.format)
print(df["dateTime"])
1

There are 1 best solutions below

2
Poder Psittacus On

Have you tried:

df['dateTime'] = df['dateTime'].str.zfill(18)