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的价格文本去掉了$,转换成浮点型,并求平均值。

posted @ 2017-09-06 15:00  imageSet  阅读(784)  评论(0编辑  收藏  举报