我爱编程

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

2017-11-09  本文已影响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使用技巧总览

上一篇 下一篇

猜你喜欢

热点阅读