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

简介: 本文生成新的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使用技巧总览

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容