DataFrame鏇挎崲涓枃value

鐪熸槸蹇冪疮鍟婏紝杩欑楝奸棶棰樺洶鎵颁簡蹇竴澶╋紝鐧惧害鍚勭鎼滀笉鍒扮瓟妗堬紝鍏ㄦ槸鍦ㄨread_csv鍔爀ncoding gbk2312鎴栬�単bk鐨勶紝閫楁垜銆傘�傘�傘�傘�傘��
鏈�鍚庢眰鍔╄胺姝岀埜鐖告墠瑙e喅锛屾煇搴﹀徃涓鍚э紝灏辩煡閬撴敹鎺ㄥ箍璐癸紝鎺ㄨ崘閮芥槸浠�涔堝瀮鍦撅紝閱変簡 - -

闂

鏁版嵁濡備笅


DataFrame鏇挎崲涓枃value_第1张图片

鎴戦渶瑕佹妸age鏍忕殑涓枃鍏ㄩ儴鍘绘帀锛屾浛鎹㈡垚鏁板瓧锛�0锛�1锛�2绛夌瓑
鐩存帴瀵筍eries杩涜replace("15宀佷互涓�",0)鏄け璐ョ殑锛屽洜涓哄拰瑙g爜鏈夊叧锛宲ython涓嶈璇嗕綘鐨勪腑鏂囧瓧绗︺��

瑙e喅鍔炴硶

寰堢畝鍗曪紝鍦�"15宀佷互涓�"鍓嶉潰鍔犱竴涓猽锛屽嵆u"15宀佷互涓�"锛岃繖鏍穚ython灏辩煡閬撲綘鏄浛鎹㈢殑鏄腑鏂囷紝浠庤�屽搴旇В鐮�

user = pd.read_csv("input/JData_User.csv",encoding="gbk")
user.info(null_counts = True)

鍙互鐪嬪埌锛岀幇鍦╝ge鐨勭被鍨嬫槸object


RangeIndex: 103616 entries, 0 to 103615
Data columns (total 5 columns):
user_id        103616 non-null int64
age            103616 non-null object
sex            103616 non-null int64
user_lv_cd     103616 non-null int64
user_reg_dt    103616 non-null object
dtypes: int64(3), object(2)
memory usage: 4.0+ MB

瀵逛腑鏂囪繘琛屾浛鎹紝浣跨敤list锛岃繘琛屾壒閲忔浛鎹紝鐒跺悗灏哸ge鐨勭被鍨嬭浆鎹负int

user['age'].replace(["-1",u"15宀佷互涓�",u"16-25宀�",u"26-35宀�",u"36-45宀�",u"46-55宀�",u"56宀佷互涓�"] , [-1,0,1,2,3,4,5] , inplace=True)
user['age']=user['age'].astype(int)
user.info(null_counts=True)

RangeIndex: 103616 entries, 0 to 103615
Data columns (total 5 columns):
user_id        103616 non-null int64
age            103616 non-null int64
sex            103616 non-null int64
user_lv_cd     103616 non-null int64
user_reg_dt    103616 non-null object
dtypes: int64(4), object(1)
memory usage: 4.0+ MB

鏌ョ湅鏁版嵁,杞崲鎴愬姛


DataFrame鏇挎崲涓枃value_第2张图片

你可能感兴趣的:(DataFrame鏇挎崲涓枃value)