我首先使用BeautifulSoup:
mydivs = soup.findAll('div', {"class": "content"})
使mydivs
中的每个mydiv
看起来像这样,例如:
然后我想将每个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
。我该怎么解决这个问题?在
形状是
DF
的属性。该属性是tuple
。您正试图用抛出错误的()
调用它。如果你想要这个形状,只要做DF.shape
不是
^{pr2}$相关问题 更多 >
编程相关推荐