#数据处理中使用函数解析:
##json.load()与json.loads()的区别
json.loads() #将json string解析为python dictionary
json.load() #将json object解析为python dictionary
简单示例:
##dictionary默认值设定
my_dict.setdefault('a',[]) #将my_dict['a']默认值设为list
my_dict = dict() #如果不初始化直接引入my_dict['a']会提示出错
my_dict = collections.defaultdict(list) #将my_dict的各个key的value默认为list
简单示例:
##collections.Counter(iterable)
from collections import Counter
Counter(list) #counting the number of elements of list,return Counter dictionary object
Counter(dictionary) #return Counter dictionary object
#Counter() support three methods:
Counter.elements() #根据Counter dictionary中value值,返回Counter key
Counter.most_common(n=10) #返回最常见的n个(key,value)
Counter1.subtract(Counter2) #返回Counter1 - Counter2的差值
简单示例:
##list.sort()与sorted()的区别
list.sort(reverse=True) #sort()是应用在list上的方法
sorted(iterable,key,reverse=True) #sorted()是应用在所有可迭代对象上的,返回一个新的iterable
简单示例:
##series.notnull()
简单示例:
##series.str
series.str #返回的是pandas string_object,其具有一些StringMethods
series.str.split('')
series.str.replace('o','t')#将series中的o用t代替,返回为series
series.str.contains('a')#series各个元素是否包含a,返回boolean series
##series.nlargest(10)
简单示例:
#数据分析代码
github地址