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

3
  • 1
    You need to reassign df=df.append(entry) Commented Jun 23, 2020 at 19:06
  • @ScottBoston thanks that did help, but now my contents are vertical instead of horizontal. Commented Jun 23, 2020 at 19:08
  • Try, df.append(dict(zip(df.columns, entry)), ignore_index=True) Commented Jun 23, 2020 at 19:15

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.