'How to retain leading 0's when converting xml to csv
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"])
Solution 1:[1]
Have you tried:
df['dateTime'] = df['dateTime'].str.zfill(18)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Poder Psittacus |
