pandas庫疑難問題---4、DataFrame類型轉換成Numpy中ndarray
一、總結
一句話總結:
可以使用DataFrame中的values屬性或to_numpy方法 和 Numpy中的array方法
ans=df.values ans=df.to_numpy() ans=np.array(df)
二、DataFrame類型轉換成Numpy中ndarray
博客對應課程的視頻位置:4、DataFrame類型轉換成Numpy中ndarray-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/381
import pandas as pd import numpy as np df = pd.DataFrame(np.arange(20).reshape((4,5)),index=list("ABCD"),columns=list("vwxyz")) print(df)
可以使用DataFrame中的values屬性或to_numpy方法 和 Numpy中的array方法
1、使用DataFrame中的values屬性或to_numpy方法
In [6]:
# dir(df)
values屬性
In [3]:
ans=df.values print(type(ans)) print(ans)
to_numpy方法
In [4]:
ans=df.to_numpy() print(type(ans)) print(ans)
2、使用Numpy中的array方法
In [5]:
ans=np.array(df) print(type(ans)) print(ans)
In [ ]:
博客對應系列課程視頻位置:
1、pandas打亂數據集-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/360
2、pandas切片操作-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/379
3、loc方法和iloc方法的區別-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/380
4、DataFrame類型轉換成Numpy中ndarray-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/381
1、pandas打亂數據集-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/360
2、pandas切片操作-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/379
3、loc方法和iloc方法的區別-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/380
4、DataFrame類型轉換成Numpy中ndarray-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/39/381
