@@ -1058,7 +1058,7 @@ def read_xml(
1058
1058
1059
1059
Examples
1060
1060
--------
1061
- >>> import io
1061
+ >>> from io import StringIO
1062
1062
>>> xml = '''<?xml version='1.0' encoding='utf-8'?>
1063
1063
... <data xmlns="http://example.com">
1064
1064
... <row>
@@ -1078,7 +1078,7 @@ def read_xml(
1078
1078
... </row>
1079
1079
... </data>'''
1080
1080
1081
- >>> df = pd.read_xml(io. StringIO(xml))
1081
+ >>> df = pd.read_xml(StringIO(xml))
1082
1082
>>> df
1083
1083
shape degrees sides
1084
1084
0 square 360 4.0
@@ -1092,7 +1092,7 @@ def read_xml(
1092
1092
... <row shape="triangle" degrees="180" sides="3.0"/>
1093
1093
... </data>'''
1094
1094
1095
- >>> df = pd.read_xml(io. StringIO(xml), xpath=".//row")
1095
+ >>> df = pd.read_xml(StringIO(xml), xpath=".//row")
1096
1096
>>> df
1097
1097
shape degrees sides
1098
1098
0 square 360 4.0
@@ -1118,14 +1118,42 @@ def read_xml(
1118
1118
... </doc:row>
1119
1119
... </doc:data>'''
1120
1120
1121
- >>> df = pd.read_xml(io. StringIO(xml),
1121
+ >>> df = pd.read_xml(StringIO(xml),
1122
1122
... xpath="//doc:row",
1123
1123
... namespaces={{"doc": "https://example.com"}})
1124
1124
>>> df
1125
1125
shape degrees sides
1126
1126
0 square 360 4.0
1127
1127
1 circle 360 NaN
1128
1128
2 triangle 180 3.0
1129
+
1130
+ >>> xml_data = '''
1131
+ ... <data>
1132
+ ... <row>
1133
+ ... <index>0</index>
1134
+ ... <a>1</a>
1135
+ ... <b>2.5</b>
1136
+ ... <c>True</c>
1137
+ ... <d>a</d>
1138
+ ... <e>2019-12-31 00:00:00</e>
1139
+ ... </row>
1140
+ ... <row>
1141
+ ... <index>1</index>
1142
+ ... <b>4.5</b>
1143
+ ... <c>False</c>
1144
+ ... <d>b</d>
1145
+ ... <e>2019-12-31 00:00:00</e>
1146
+ ... </row>
1147
+ ... </data>
1148
+ ... '''
1149
+
1150
+ >>> df = pd.read_xml(StringIO(xml_data),
1151
+ ... dtype_backend="numpy_nullable",
1152
+ ... parse_dates=["e"])
1153
+ >>> df
1154
+ index a b c d e
1155
+ 0 0 1 2.5 True a 2019-12-31
1156
+ 1 1 <NA> 4.5 False b 2019-12-31
1129
1157
"""
1130
1158
check_dtype_backend (dtype_backend )
1131
1159
0 commit comments