zoukankan      html  css  js  c++  java
  • Pandas学习笔记,字符串方法(string method),转换数据类型,方法连写等等。

    一般语法格式Series.str.method()。具体方法见http://pandas.pydata.org/pandas-docs/stable/api.html#string-handling

    例如

    Series.str.capitalize()

    作用:Convert strings in the Series/Index to be capitalized.

    Pandas可以将DataFrame中的数据格式进行改变,如字符串改为数字格式为

    DataFrame.astype(dtype)

    只修改一列的话

    DataFrame.Series.astype(dtype)

    另外各种方法可以连写,实现一次性对数据的处理,例如:

    order.item_price.str.replace('$', '').astype(float).mean()

    把一列格式为$4的价格文本去掉了$,转换成浮点型,并求平均值。

  • 相关阅读:
    Vue-dialog(弹框组件)
    Vue封装select下拉组件
    RAID总结
    消息队列
    存储
    算法开始
    硬件杂记
    要看的
    关于kernel的疑问,不解
    杂技
  • 原文地址:https://www.cnblogs.com/imageSet/p/7484830.html
Copyright © 2011-2022 走看看