Reputation:
datum = soup.findAll('a', {'class': 'result-title'})
for data in datum:
print(data.text)
print(data.get('href'))
df = {'Title': data.text, 'Url': data.get('href')}
houseitems.append(df, ignore_index=True)
What is wrong with my Code? Why when I asked for my houseitems, it gives me empty data.
Empty DataFrame
Columns: [Title, Url, Price]
Index: []
Upvotes: 35
Views: 74512
Reputation: 862851
Problem is you need assign back appended DataFrame
, because pandas DataFrame.append
NOT working inplace like pure python append
.
It seem you want append to list
, so parameter ignore_index=True
is not necessary:
Loop solution:
houseitems = []
for data in datum:
print(data.text)
print(data.get('href'))
df = {'Title': data.text, 'Url': data.get('href')}
houseitems.append(df)
Or list comprehension
solution:
houseitems = [{'Title': data.text, 'Url': data.get('href')} for data in datum]
And then create DataFrame
:
df1 = pd.DataFrame(houseitems)
Upvotes: 36
Reputation: 1333
Try modify line in your code
houseitems.append(df, ignore_index=True)
as
houseitems=houseitems.append(df, ignore_index=True)
Upvotes: 96