What are Python pandas equivalents for R functions like str(), summary(), and head()?

后端 未结 7 1090
别跟我提以往
别跟我提以往 2020-11-29 21:26

I\'m only aware of the describe() function. Are there any other functions similar to str(), summary(), and head()?

7条回答
  •  隐瞒了意图╮
    2020-11-29 21:55

    This provides output similar to R's str(). It presents unique values instead of initial values.

    def rstr(df): return df.shape, df.apply(lambda x: [x.unique()])
    
    print(rstr(iris))
    
    ((150, 5), sepal_length    [[5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.4, 4.8, 4.3,...
    sepal_width     [[3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 2.9, 3.7,...
    petal_length    [[1.4, 1.3, 1.5, 1.7, 1.6, 1.1, 1.2, 1.0, 1.9,...
    petal_width     [[0.2, 0.4, 0.3, 0.1, 0.5, 0.6, 1.4, 1.5, 1.3,...
    class            [[Iris-setosa, Iris-versicolor, Iris-virginica]]
    dtype: object)
    

提交回复
热议问题