0

I am trying to parse through housing data I scraped off of the web. For each house, I am storing the characteristics within a list. I want to put each house's characteristics (e.g., bedrooms, bathrooms, square feet, etc.) into a row of the same pandas dataframe. However, when I try the code below, the headers of my dataframe appear, but not any of the contents. What am I missing here?

def processData(url):
    
    #Rest of function omitted as it is not relevant to the question at hand.
    
    entry = [location, price, beds, baths, sqft, lotSize, neighborhoodMed, dom, built, hs, 
          garage, neighborhood, hType, basementSize]

    df = pd.DataFrame(columns = ["Address", "Price", "Beds", "Baths", "SqFt", "LotSize", 
                                 "NeighborhoodMedian", "DOM", "Built", "HighSchool", "Garage", 
                                "Neighborhood", "Type", "BasementSize"])

    df.append(entry) #This line doesn't work
    
    return df

Output: enter image description here

324
  • 702
  • 8
  • 28

1 Answers1

1

Just guessing as to your requirements but try the following

import pandas as pd

location, price, beds, baths, sqft, lotSize, neighborhoodMed, dom, built, hs, garage, neighborhood, hType, basementSize = range(
    14)
entry = [
    location, price, beds, baths, sqft, lotSize, neighborhoodMed, dom, built,
    hs, garage, neighborhood, hType, basementSize
]

columns = [
    "Address", "Price", "Beds", "Baths", "SqFt", "LotSize",
    "NeighborhoodMedian", "DOM", "Built", "HighSchool", "Garage",
    "Neighborhood", "Type", "BasementSize"
]

df = pd.DataFrame(columns=columns)

df = df.append(
    dict(zip(columns, entry)), ignore_index=True)  #This line doesn't work

print(df)