I got it to work once, but did not save the file and lost the code. Please help.
import pandas as pd
import nltk
df0.head(4)
# X Y month day FFMC DMC DC
# 0 7 5 mar fri 86.2 26.2 94.3
# 1 7 4 oct tue 90.6 35.4 669.1
monthdict={'jan':1,'feb':2'mar':3,'oct':10,'nov':11,'dec':12}
def month2num(month):
return monthdict[month]
df0['month'] = df0['month'].apply(month2num)
df0.head()
'Comment' I am not that smart, and just getting started, so kindly would someone please explain the solution in English.
Error printout below:
# KeyError
# Traceback
# (most recent call last)
# <ipython-input-48-566f3675aaed> in <module>()
# def month2num(month):
# return monthdict[month]
# ----> df0['month'] = df['month'].apply(month2num)
# df0.head()
# 1 frames
# pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
# <ipython-input-48-566f3675aaed> in month2num(month)
#
# def month2num(month):
# ----> return monthdict[month]
# df0['month'] = df['month'].apply(month2num)
# df0.head()
# KeyError: 'apr'