'How to use python .concat to add web scrape text to DataFrame?

Please someone show me how to add my results( address,distance etc) into my london_data dataframe i am stuck here

london_data = pd.DataFrame(columns=['Address', 'Bedrooms', 'Distance', 'Date Listed', 'Rent'])

for row in soup.find('div', class_='css-1itfubx e19tytbu0').find_all('div', class_='e19tytbu1 css-1x0ju0p esqwi9k19'):
    address = row.find('p', class_='css-5agpw4 esqwi9k33').text
    bedrooms = row.find('p', class_='css-r8a2xt-Text eczcs4p0').text
    distance = row.find('p', class_='css-nwapgq-Text eczcs4p0').text
    date_listed = row.find('span', class_='css-dwkus2 esqwi9k34').text
    rent = row.find('p', class_='css-1w7anck esqwi9k31').text.strip(' pcm').strip('£')
    


Solution 1:[1]

Try this:

london_data = pd.DataFrame(
    {
        "Address": pd.Series(adress),
        "Bedrooms": pd.Series(bedrooms),
        "Distance": pd.Series(distance),
        "Date Listed": pd.Series(date_listed),
        "Rent": pd.Series(rent),
    }
)

No need in defining the df with columns only before. pd.Series is only needed in case your scraped data has different length

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rabinzel