1
我有一個空的熊貓數據框中添加數據到數據幀的熊貓:Python 3.x都有使用循環
aqi_df = pd.DataFrame(columns = ["IMEI","Date","pm10conc_24hrs","pm25conc_24hrs","sdPm10","sdPm25","aqi","windspeed","winddirection","severity","health_impact"])
我想通過一個添加到每一列的元素一個 -
for i in range(1,10):
aqi_df.IMEI.append("a")
aqi_df.Date.append("b")
aqi_df.pm10conc_24hrs.append("c")
.
.
.
但追加拋出錯誤
TypeError: cannot concatenate a non-NDFrame object
如何將元素逐個追加到熊貓數據框?
錯誤很明顯,你需要傳遞一個'Series'或' DataFrame'用於追加,除此之外爲什麼在非高性能時執行此操作,因爲您將在每次追加調用時迭代增加df,因此速度會很慢 – EdChum