最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pandas.DataFrame.from_dict直接從字典構(gòu)建DataFrame的方法

 更新時間:2022年06月17日 09:46:38   作者:旺仔的算法coding筆記  
本文主要介紹了pandas.DataFrame.from_dict直接從字典構(gòu)建DataFrame的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

pandas函數(shù)中pandas.DataFrame.from_dict 直接從字典構(gòu)建DataFrame 。

參數(shù)解析

DataFrame from_dict()方法用于將Dict轉(zhuǎn)換為DataFrame對象。 此方法接受以下參數(shù)。

  • data: dict or array like object to create DataFrame.data :字典或類似數(shù)組的對象來創(chuàng)建DataFrame。
  • orient: The orientation of the data. The allowed values are (‘columns’, ‘index’), default is the ‘columns’.  orient :數(shù)據(jù)的方向。 允許值為(“列”,“索引”),默認值為“列”。 Specify orient='index' to create the DataFrame using dictionary keys as rows:。 當參數(shù)orient為index值時,會將字典的keys作為DataFrame的行。(默認是keys變?yōu)榱校?/li>
  • columns: a list of values to use as labels for the DataFrame when orientation is ‘index’. If it’s used with columns orientation, ValueError is raised.     columns :當方向為“索引”時,用作DataFrame標簽的值的列表。 如果與列方向一起使用,則會引發(fā)ValueError 。

實例  

1)By default the keys of the dict become the DataFrame columns:

默認是將字典的keys作為列

data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data)
   col_1 col_2
0      3     a
1      2     b
2      1     c
3      0     d

2) Specify orient='index' to create the DataFrame using dictionary keys as rows: 參數(shù)orient為index值時,會將字典的keys作為DataFrame的行

data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index')
       0  1  2  3
row_1  3  2  1  0
row_2  a  b  c  d

3) orient為index值時, 可以手動命名列名

pd.DataFrame.from_dict(data, orient='index',
                       columns=['A', 'B', 'C', 'D'])
       A  B  C  D
row_1  3  2  1  0
row_2  a  b  c  d

參考: pandas.DataFrame.from_dict — pandas 1.3.4 documentation

到此這篇關(guān)于pandas.DataFrame.from_dict直接從字典構(gòu)建DataFrame的方法的文章就介紹到這了,更多相關(guān)pandas字典構(gòu)建DataFrame內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

翁源县| 吉林省| 珲春市| 柳州市| 蒲城县| 阳新县| 莱阳市| 阿瓦提县| 自治县| 天祝| 嘉善县| 合江县| 东安县| 方城县| 怀仁县| 长宁县| 荆门市| 乌拉特后旗| 西吉县| 慈利县| 洛浦县| 临澧县| 萨迦县| 建德市| 新平| 海阳市| 宜川县| 厦门市| 四会市| 襄垣县| 临城县| 正定县| 汉寿县| 来宾市| 晋州市| 疏勒县| 大邑县| 诏安县| 凉山| 衡南县| 鞍山市|