2
我第一次使用BeautifulSoup:熊猫pd.DataFrame转换成元组,而不是数据帧
mydivs = soup.findAll('div', {"class": "content"})
使得mydivs
每个mydiv
看起来像这样的例子:
<div class="content">A number of hats by me <br/><br/>three now though ... </div>
我再要存储每个每个div
中的文本块作为数据帧中的行。我想数据框看起来是这样的:
index posts
0 <div class="content">A number of <br/><br/>three ... </div>
1 <div class="content">Stack ... <br/><br/>overflow ... </div>
...
这是我尝试
A=[]
indices=[]
j=0
for div in mydivs:
A.append(div)
indices.append(j)
j+=1
DF = pd.DataFrame({'index': indices, "posts": A})
的代码时,我然后打印出shape
我得到
print DF.shape()
TypeError: 'tuple' object is not callable
不过,我想DF
成为数据帧,而不是tuple
。我怎样才能解决这个问题?