【发布时间】:2017-08-26 16:16:49
【问题描述】:
我正在尝试根据以字符串形式显示的日期列表在 Pandas 中创建一个系列,因此:
['2016-08-09',
'2015-08-03',
'2017-08-15',
'2017-12-14',
...
但是当我从 Pandas 模块中应用 pd.Series 时,Jupyter 笔记本中的结果显示为:
0 [[[2016-08-09]]]
1 [[[2015-08-03]]]
2 [[[2017-08-15]]]
3 [[[2017-12-14]]]
...
有没有简单的方法来解决它?数据来自使用 lxml.objectify 解析的 Xml 提要。
从 csv 读取数据时,我通常不会遇到这些问题,只是好奇我可能做错了什么。
更新:
获取数据的代码和示例站点:
导入 lxml.objectify 将熊猫导入为 pd
def parse_sitemap(url):
root = lxml.objectify.parse(url)
rooted = root.getroot()
output_1 = [child.getchildren()[0] for child in rooted.getchildren()]
output_0 = [child.getchildren()[1] for child in rooted.getchildren()]
return output_1
results = parse_sitemap("sitemap.xml")
pd.Series(results)
【问题讨论】:
-
您可以发布实际输入和您用于转换为系列的代码吗?使用
pd.Series()包装您的示例数据不会在我的 Jupyter 笔记本中产生该输出。 -
“申请
pd.Series”是什么意思?
标签: python pandas lxml series lxml.objectify