pandas dataframe 循环,python dataframe 遍历

  pandas dataframe 循环,python dataframe 遍历

  www.Sina.com/importpandasaspdimportnumpyasnp http://www.Sina.com/#街3358号数据框对象df=PD.data frame ([ 1,2,2,2,3,4,4)])" e "(printdfcolsa 1 B2C 3d 4e 5d F2=PD。数据帧([1,2,3 ],[ 4,5,6]" b ))print df 2 col 1 col 2 col 3a 123 b 456 df 3 b )print df 3c ol 1 col 2 a 12 b 34 df4=PD。数据帧((col 1 :(1,3),col 2 )(2,4))、索引=(a a用于创建L1 col2a 12 b 34数据帧对象的数据包括列表、数组和词典,列名和索引为列表对象http://www .新浪df2。index index((u dype= object (df2。列索引([u col 1 ,ucol2 ,ucol2 ,ucol2 )),dtype=object )基于该索引(数据df2.loc))的一种显示方式是数字索引存取数据第一栏、第二栏、第三栏、第三栏、名称:a、dtype 3360、int 64、print 64通过基于" b]] #访问多行数据,索引参数是列表对象col 1 col 2 col3a 123 b 456 printdf。loc[df。index[1:3]]返回

  #数据帧要素的合计#默认情况下,各列的要素的合计打印df2.sum(第15列第27列第39d列类型:int 64)行的合计printdf2.sum )1)一个6b 15dtype: int64 #。将每个元素乘以2打印2 .apply(lambdax:x * 2)col 1 col 2 col3a 2 4 6b 8 10 12 #)以平方每个元素(支持与多维数组类似的矢量化操作) 2对col 1 col 2 col 3a 149 b 162536http://www。Sina.com/#数据帧对象执行列扩展df2[col4]=[cnn , rnn printdf 2 col 1 col 2 col 3c ol4a 123 cnnb 456 rnn #自动与df2 ["col 5"]=PD.data帧("加工")相对应索引=[ a ,b ])printdf 2 col 1 col 2 col 3c ol 4co l5 a123 cnnmachinelearning b 456 rnn了解http://www。Sina.com/#行扩展apppend(列2) :8,(列3 ) :9,(列4):(列4 ) 3360,(rcnn)的索引=[ c ]()col 1 col 2 col 3c ol 4co l5 a123 cnnmachinelearning b 456 rnn deplearning c 789 rcnnreinforcementlearning 3358 ww。新力量学习356如果不指定索引的参数,该索引将显示printdf 2。append({ col 1 :10, col 2 :11, col 3 :12、ignore _ index=true(col 1 col 2 col 3c ol 4 col 501223 cnnmachinelearning 1456 rnndeeplearning 21010)的数字替换df2这一数据类型#以上的行尚未修改,df2=df2。追加(PD。数据帧(col 1):7, col2:8, col3:9, col 4) col index=[ c ])printdf 2 col 1 col 2 col 3c ol 4co l5 a123 cnnmachinelearning b 456 rnn deplearning c 789 rcnnnrenforcementlearning arni ngprintdf 2。loc 1 col 3c ol 4co l5 c 789 rcnnreinforcementlearning c 789 rcnnreinforcement learning 3358 www。Sina.com数据框对象的合并df _ a= hui , is , a , master], columns=[ col 6 ] f ])printdf _ acol 6 awangbjinguidiseafmaster #默认的列ent g )printdfb。加入(df _ a)col 1 col 6a 1 col万gb2京4惠是F6高手G7 nan)接受默认合并的索引已存在的值(如果有)指定合并方法的printDFB.join ) ) ) ) how=inner ) #两个数据帧对象的交集col 1 col 6a 1万gb2京4惠是F6大师#两个how= outer (col 1 col 6a 1.0 wangb 2.0 Jing 4.0 huid 5.0 isen anaf 6.0 masterg 7.0 nan安利一下,公众号:白痴网才是食神

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: