我正在逐项解析一个项目列表到pandas append函数中。 pandas.DataFrame.append
from pyquery import PyQuery as pq
import pandas as pd
import argparse
# from glob import glob
parser = argparse.ArgumentParser(description=None)
def GetArgs(parser):
"""Parser function using argparse"""
# parser.add_argument('directory', help='directory use',
# action='store', nargs='*')
parser.add_argument("files", nargs="+")
return parser.parse_args()
fileList = GetArgs(parser)
print(fileList.files)
data = []
frames = pd.DataFrame()
attrs = ('id', 'horse')
for items in fileList.files:
d = pq(filename=items)
res = d('nomination')
dataSets = [[res.eq(i).attr(x)
for x in attrs] for i in range(len(res))]
print(dataSets)
aDF = pd.DataFrame(dataSets,)
frames.append(aDF)
print(frames)
我可以从输出中看到我获取数据,并且我正在将一个列表列表解析为要附加的dfame但是它运行一个空的数据帧
(pyquery)sayth@sayth-E6410:~/Projects/pyquery$ python jqxml.py samples/*.xml
['samples/20160402RAND0.xml']
[['198247', 'Astern'], ['199039', 'El Divino'], ['199616', 'Geneteau'], ['197890', 'Alliterate'], ['201416', 'Hostwin Legend'], ['202829', 'Lionhearted'], ['199619', 'Mooshakissa'], ['202345', "Let's Dream Big"], ['200794', 'Prince Chabal'], ['202766', 'Red Handle'], ['198442', "He's Our Rokkii (NZ)"], ['188683', 'Odyssey Moon'],
...
['193862', 'Karaka Lass'], ['193850', 'Alittle Loose'], ['191829', "Aurora's Star"], ['196396', 'Shanakee (NZ)'], ['192985', 'Rainbow Park (NZ)'], ['192983', "Daisy's Joy"], ['198039', 'Shotgun Roulette'], ['188872', "Peggy's Cove"], ['188981', 'Heartlings']]
Empty DataFrame
Columns: []
Index: []
不确定为什么不添加。
答案 0 :(得分:1)
问题是append
不是熊猫中的一个就地功能;它返回附加的结果。因此,您需要重新定义frames
作为附加结果:
frames = frames.append(aDF)