分类:PYTHON
创建category使用Series创建在创建Series的同时添加dtype="category"就可以创建好category了。category分为两部分,一部分是order,一部分是字面量:In[1]:s=pd.Series(["a","b","c","a"],dtype="category")In[2]:sOut[2]:0a1b2c3adtype:categoryCategories(3,object):['a','b','c']可以将DF中的Series转换为category:In[3]:df=pd.DataFrame({"A":["a","b","c","a"]})In[4]:df["B"]=...
继续阅读 >
1、使用dict()函数,通过其他映射(比如其他字典)或者键,值对的序列建立字典。dict1=dict(a='a',b='b',t='t')#传入关键字print(dict1)dict2=dict(zip(['one','two','three'],[1,2,3]))#映射函数方式来构造字典print(dict2)dict3=dict([('one',1),('two',2),('three',3)])#可迭代对象方式来构造字典print(dict3)2、使用fromkeys()函数,只用来创建新字典,不负责保存。当通过一个字典来调用f...
继续阅读 >