Skip to content

Instantly share code, notes, and snippets.

class MyType(type):
def __init__(cls, what, bases=None, dict=None):
print 'call myType.__init__()'
print "class name:"+what
print "class bases:"+str(bases)
print "class attributions:"+str(dict)
super(MyType,cls).__init__(what, bases, dict)
def __new__(cls, name, bases, attrs):
print "call MyType.__new__()"
return type.__new__(cls, name, bases, attrs)
class num:
def __init__(self,v):
self.v=v
def double(self):
return self.v*2
x=num(2)
bound=x.double
data=pd.DataFrame([[2010,'auto'],[2010,'haha'],[2011,'haha'],[2012,'md']],columns=['year','type'])
data['typecnt']=np.ones(data.shape[0])
data.groupby(['year','type'])['typecnt'].count()
输出
year type
2010 auto 1
haha 1
2011 haha 1
2012 md 1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.