博客
关于我
dataframe中axisk轴的意思
阅读量:656 次
发布时间:2019-03-15

本文共 464 字,大约阅读时间需要 1 分钟。

要删除 pandas 数据框中的两列 TimeAmount,并沿着轴=1(即列]进行操作,可以通过以下步骤实现:

  • 创建数据框 df,并将其包含的数据转换为字典的形式:
  • data = {    'k1': ['o', 'm'],    'year': [2000, 2001],    'pop': [3.5, 6.5]}df = pd.DataFrame(data)
    1. 使用 drop 方法删除指定的两列:
    2. # 删除 'Time' 和 'Amount' 两列df.drop(columns=['Time', 'Amount'])
      1. 检查删除后的数据框:
      2. print(df)

        这一方法通过在 columns 参数中指定需要删除的列名,直接实现垂直方向上的数据截取,不会受到列名唯一性的影响。需要注意的是,要确保删除的列名与数据框的当前列名匹配。如果有参数错误或版本问题,可以使用 df.drop(columns=[...]) 这种更直接的方式。

        通过这种方式,可以依靠 pandas 的强大功能简化操作,并确保数据处理的准确性。

    转载地址:http://atrmz.baihongyu.com/

    你可能感兴趣的文章
    notepad++最详情汇总
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>