【问题标题】:How to get the same data.frame with Data.Frame in pandas module of python?python - 如何在python的pandas模块中获得与Data.Frame相同的data.frame?
【发布时间】:2015-01-05 07:59:32
【问题描述】:

在R中,我们可以得到x和y这两个data.frame。

> x=data.frame(matrix(1:12,nrow=2,byrow=TRUE))
> y=data.frame(matrix(1:12,nrow=2,byrow=FALSE))
> x
  X1 X2 X3 X4 X5 X6
1  1  2  3  4  5  6
2  7  8  9 10 11 12
> y
  X1 X2 X3 X4 X5 X6
1  1  3  5  7  9 11
2  2  4  6  8 10 12
> 

如何在python的pandas模块中获取与Data.Frame相同的data.frame,在python的pandas模块中使用Data.Frame获取x和y?

【问题讨论】:

    标签: python r pandas dataframe


    【解决方案1】:
    >>> import numpy as np
    >>> import pandas as pd
    
    >>> x = pd.DataFrame(np.arange(1,13).reshape(2,-1))
    >>> y = pd.DataFrame(np.arange(1,13).reshape(-1,2).T)
    
    >>> x
       0  1  2   3   4   5
    0  1  2  3   4   5   6
    1  7  8  9  10  11  12
    
    >>> y
       0  1  2  3   4   5
    0  1  3  5  7   9  11
    1  2  4  6  8  10  12
    

    【讨论】:

    • 请添加一行import numpy as np
    猜你喜欢
    • 2018-01-23
    • 2023-03-31
    • 2015-03-11
    • 2020-11-27
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    相关资源
    最近更新 更多