Python之Pandas:利用pandas實作行資料添加,即將字典格式的資料,按照行資料回圈添加到dataframe中
目錄
利用pandas實作行資料添加,即將字典格式的資料,按照行資料回圈添加到dataframe中
實作代碼
輸出結果
利用pandas實作行資料添加,即將字典格式的資料,按照行資料回圈添加到dataframe中
實作代碼
#行資料添加:將字典格式的資料,按照行資料回圈添加到dataframe中
import pandas as pd
dataf=pd.DataFrame(columns=['keys','values'], index=[])
i=0
for name, hex in data_dict.items():
dataf.loc[i] = [name, hex]
i+=1
print(dataf)
輸出結果
keys values
0 aliceblue #F0F8FF
1 antiquewhite #FAEBD7
2 aqua #00FFFF
3 aquamarine #7FFFD4
4 azure #F0FFFF
.. ... ...
143 wheat #F5DEB3
144 white #FFFFFF
145 whitesmoke #F5F5F5
146 yellow #FFFF00
147 yellowgreen #9ACD32
CSDN認證博客專家
華為杯研電賽一等
華為研數模一等獎
國內外AI競十
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/253484.html
標籤:python
上一篇:6、python串列——旺仔
下一篇:爬蟲神器scrapy的安裝
