美文网首页我爱编程
pandas使用技巧【19】如何根据DataFrame生成新的D

pandas使用技巧【19】如何根据DataFrame生成新的D

作者: 夜雨寒山 | 来源:发表于2017-11-09 14:56 被阅读0次
简介: 本文生成新的DataFrame

1.传入多个序列。
如果不指定index和columns,pandas会自动加上默认的数字化序列。

pd.DataFrame(  [100, 101, 102, 103],  ["red", "blue", "red", "yellow"])
pd.DataFrame( np.random.rand(4, 2))

pd.DataFrame( [100, 101, 102, 103],   ["red", "blue", "red", "yellow"], columns=["id", "color"], index = ["a", "b", "c", "d"]})
pd.DataFrame(np.random.rand(4, 2),  columns= ["one", "two", "three", "four"], index = ["a", "b", "c", "d"]})
  1. 传入字典参数。
    传入的字典的key会被当作columns。
pd.DataFrame({"id": [100, 101, 102, 103], "color": ["red", "blue", "red", "yellow"]})
pd.DataFrame({"id": [100, 101, 102, 103], "color": ["red", "blue", "red", "yellow"], columns=["id", "color"], index = ["a", "b", "c", "d"]})

附上小哥哥的视频链接Data analysis in Python with pandas
Youtube 🔗
哔哩哔哩 🔗

本系列文章列表
pandas使用技巧总览

相关文章

网友评论

    本文标题:pandas使用技巧【19】如何根据DataFrame生成新的D

    本文链接:https://www.haomeiwen.com/subject/zoopmxtx.html