【发布时间】:2020-10-13 22:35:52
【问题描述】:
我正在尝试解析我从网络上抓取的住房数据。对于每所房子,我将特征存储在一个列表中。我想将每个房子的特征(例如卧室、浴室、平方英尺等)放入同一 pandas 数据框中的一行。但是,当我尝试下面的代码时,我的数据框的标题出现了,但没有任何内容。我在这里错过了什么?
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
【问题讨论】:
-
您需要重新分配
df=df.append(entry) -
@ScottBoston 谢谢你的帮助,但现在我的内容是垂直的而不是水平的。
-
试试看,
df.append(dict(zip(df.columns, entry)), ignore_index=True)
标签: python python-3.x pandas dataframe append