python分类为循环

时间:2018-05-09 08:13:52

标签: python python-3.x pandas for-loop

嗨我想问一下python for loop logic。 这是一些数据。

art1 = ["A",'B','C','D','E','F']
quote = ["",'A','A','C','C','A']
g2 = pd.DataFrame({"Article":art1,"Quote":quote})

引用B,C,F和C由D和E引用。 所以我写了一个for循环。

dic = []
dic2 = []
for i in range(0,len(art1)) :
   dic.append(art1[i])
   dic2.append("")
   for j in range(1,len(quote)):
       if art1[i] == quote[j]:
            dic2.append(art1[j])
            dic.append("")
g3 = pd.DataFrame(OrderedDict({"Article":dic,"Quote":dic2}))

enter image description here

但C引用了A. D和E引用了C.所以我想将D和E放在A类中。 请...我该如何编码呢?​​

This is the format I want.

0 个答案:

没有答案