相同的功能,不同的大小写



我从网络上报废了数据帧,其中包含来自用户输入数据的特征。但是,我的一些专栏包含有关汽车的功能,对于同一功能具有不同的大写形式,即"加热座椅"和"加热座椅"。这些是虚拟变量,因此带有加热座椅的汽车的一列为零,另一列为1。最终目标是添加具有相同功能的所有列,只是大小写不同。有谁知道任何库可以帮助循环浏览数百个特征来检查像这样大小写不匹配的对?

谢谢

让我们以python字典格式取两列。前任:

 python_dict = {'Heated Seats':0, 'heated seats':1}
 sum = 0
 reference_string = 'HEATED SEATS'  #Take the reference string here just to compare. In your case no need to take.
 for key in python_dict.keys():
     if key.lower() == reference_string.lower():
        #Adding the values of Heated seats car values
        sum = sum + python_dict[key]
 print sum

最新更新