开发者社区> 问答> 正文

Python中cut函数的示例是什么呢?

Python中cut函数的示例是什么呢?

展开
收起
游客qzzytmszf3zhq 2021-11-30 15:01:28 298 0
1 条回答
写回答
取消 提交回答
  • import pandas as pd
     
    data = [3, 60, 83, 100, 52, 36]#源数据
    w = [0, 25, 50, 75, 100]#规定了分类的边界
    v = 4 #仅规定分类的个数,不规定边界值
    data_cut1 = pd.cut(data, w)
    data_cut2 = pd.cut(data, v)
    print("规定了分类的边界:\n", data_cut1)
    print("\n规定了分类的个数:\n", data_cut2)
    
    
    运行结果:
    规定了分类的边界:
     [(0, 25], (50, 75], (75, 100], (75, 100], (50, 75], (25, 50]]
    Categories (4, interval[int64]): [(0, 25] < (25, 50] < (50, 75] < (75, 100]]
    规定了分类的个数:
     [(2.903, 27.25], (51.5, 75.75], (75.75, 100.0], (75.75, 100.0], (51.5, 75.75], (27.25, 51.5]]
    Categories (4, interval[float64]): [(2.903, 27.25] < (27.25, 51.5] < (51.5, 75.7
    
    2021-11-30 15:01:49
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载