我试图将这个for循环改为apply方法,因为iterrows/itertuple都太慢了。我有一个相当大的数据集。这可能吗?在
for index, row in df2.iterrows():
startDateString = str(row['Date'].replace("/",""))
endDateString = str(row['Date'].replace("/",""))
zipcode = str(row['Zip'])
#startDateString = str(startDate)
#endDateString = str(endDate)
print("zip: " + "%s" %zipcode + ", daterange: " + startDateString + " - " + endDateString )
apply()是pandas库中速度最慢的方法之一。您可以对str属性调用执行相同的操作。 你不需要创建所有的变量。在
希望这对你的数据有用。在
为什么startDate和endDate是同一列?在
str调用与格式说明符一样是无用的。删除它们会导致:
相关问题 更多 >
编程相关推荐