One - One Code All

Blog Content

python的dataframe和matrix的互换

Python 统计学-科学计算   2014-02-12 21:58:25
import pandas as pd
import numpy as np

mat = np.random.randn(3,4)
# mat 转为  pandas
df = pd.DataFrame(mat)

# dataframe 转为 mat
mat = df.as_matrix(columns=None)


ndarray 转为矩阵:


np.mat(array)


上一篇:PANDAS 数据合并与重塑(concat篇)
下一篇:numpy常用函数np.take

The minute you think of giving up, think of the reason why you held on so long.