使用pandas中的map函数将Int转换为String

时间:2018-03-29 07:52:03

标签: anaconda jupyter-notebook jupyter anaconda-cluster

dmap = {0:'Mon',1:'Tue',2:'Wed',3:'Thur',4:'Fri',5:'Sat',6:'Sun'}
df['DayOfWeek']=df['DayOfWeek'].map(dmap)
df.head()

DayOfWeek column value is Showing as NaN rather then String

1 个答案:

答案 0 :(得分:0)

我没有完全理解你的问题,但我想它必须是那样的

dmap = {0:'Mon',1:'Tue',2:'Wed',3:'Thur',4:'Fri',5:'Sat',6:'Sun'}
       count = 0
       df = pd.DataFrame({'DayNumber':[], 'DayOfWeek': []})
       for key, value in dmap.items() :
           df.loc[count] = [str(key) , value] 
           count = count + 1 
       print(df.head())