<jupyter_start><jupyter_text>SOC<jupyter_code>df = df.dropna(subset=["處理器型號"])
soc_list = df['處理器型號'].unique()
soc_score = pd.read_csv('soc_score.csv').set_index('Unnamed: 0').T.to_dict('list')
for s in soc_list:
    s_split = str(s).split()
    if s_split[-1] == 'Bionic':
        s = 'Apple '+s.split()[0]
    elif 'MediaTek'  in s_split and 'Dimensity' in s_split:
        s = s.split()[-2] + ' '+s.split()[-1]
    elif s == 'MT6771' or s == 'MT6762V':
        s = 'Helio P60'
    elif s == 'MT6762D':
        s = 'Helio P22'
    if s not in soc_score:
        if s[:1] == 'T':
            s = 'Unisoc '+s
            if s not in soc_score:
                print(s)   
        else:
            print(s)
def soc2score(x):
    s = x['處理器型號']
    s_split = str(s).split()
    if s_split[-1] == 'Bionic':
        s = 'Apple '+s.split()[0]
    elif 'MediaTek'  in s_split and 'Dimensity' in s_split:
        s = s.split()[-2] + ' '+s.split()[-1]
    elif s == 'MT6771' or s == 'MT6762V':
        s = 'Helio P60'
    elif s == 'MT6762D':
        s = 'Helio P22'
    if s not in soc_score:
        if s[:1] == 'T':
            s = 'Unisoc '+s
    x['soc_s'] = soc_score[s][0]
    x['soc_m'] = soc_score[s][1]
    
    return x
    
df = df.apply(soc2score, axis=1)
df.columns
df = df.drop(['處理器型號', '處理器品牌', '處理器核心數'], axis=1)
df = df.drop(['處理器時脈','圖形處理器'], axis=1)
df.columns<jupyter_output><empty_output><jupyter_text>Price<jupyter_code>df['Price'] = df['Price'].apply(lambda x: int(x.replace('$', '').replace(',','')))<jupyter_output><empty_output><jupyter_text>ROM<jupyter_code>df = df.drop(['作業系統與版本'], axis=1)
df = df.dropna(subset=["ROM儲存空間"])
def handle_rom(x):
    if 'TB' in x:
        return 1024*(int(x.replace('TB', '')))
    else:
        return int(x.replace('GB', ''))
    
df['ROM儲存空間'] = df['ROM儲存空間'].apply(handle_rom)<jupyter_output><empty_output><jupyter_text>Screen<jupyter_code># df[df['主螢幕尺寸'].str.contains('inch') != True]
df['主螢幕尺寸'] = df['主螢幕尺寸'].apply(lambda x: float(str(x).replace('inch', '')))
df = df.dropna(subset=["主螢幕解析度"])
pattern_resolution = '[\d]+x[\d]+'

def handle_pix(x):
    reso = re.search(pattern_resolution, x['主螢幕解析度']).group().split('x')
    x['resolution_x'] = reso[0]
    x['resolution_y'] = reso[1]
    return x
    
df = df.apply(handle_pix, axis=1)
df = df.drop(['主螢幕解析度'], axis=1)
df['主螢幕像素密度'] = df['主螢幕像素密度'].apply(lambda x: int(x.replace('ppi', '')))
df = df.drop(['主螢幕像素密度'], axis=1)
df = df.drop(['主螢幕最大亮度', '主螢幕觸控'], axis=1)
df['OLED'] = df['主螢幕材質'].str.contains('OLED') == True
df = df.drop(['主螢幕材質'], axis=1)
df['90Hz'] = df['主螢幕更新率'].str.contains('90') == True
df['120Hz'] = df['主螢幕更新率'].str.contains('120') == True
df['144Hz'] = df['主螢幕更新率'].str.contains('144') == True
df = df.drop(['主螢幕更新率'], axis=1)
df = df.drop(['主螢幕觸控採樣率'], axis=1)<jupyter_output><empty_output><jupyter_text>Comm.<jupyter_code>df = df.drop(['4G FDD LTE', '4G TDD LTE', '3G頻率', '2G頻率', '4G LTE', 'VoLTE',
       'SIM Card類型', 'Wi-Fi'], axis=1)
df['Wifi5G'] = df['IEEE 802.11傳輸速度'].str.contains('5GH')
df['Wifi6'] = df['IEEE 802.11傳輸速度'].str.contains('6')
df = df.drop(['IEEE 802.11傳輸速度'], axis=1)
df['NFC'] = df['NFC'] == 'Yes'
df = df.drop(['藍牙', '衛星定位'], axis=1)
df['5G連網'] = (df['5G連網'] == 'Yes')
df = df.drop(['5G NR頻率', '5G NR頻段', '5G連網', 'SIM1'], axis=1)
df = df.drop(['SIM卡槽數', 'SIM卡槽設計', 'SIM2', '5G組網方式'], axis=1)
df = df.drop(['CA支援頻段組合', 'LTE Cat.', 'CA載波聚合','SIM卡槽或記憶卡擇一'], axis=1)
df = df.drop(['雙卡雙通'], axis=1)
df['藍牙版本'].value_counts()
df['bt5.0'] = (df['藍牙版本'] == 5.0)
df['bt5.1'] = (df['藍牙版本'] == 5.1)
df['bt5.2'] = (df['藍牙版本'] == 5.2)
df['bt4.2'] = (df['藍牙版本'] == 4.2)
df = df.drop(['藍牙版本'], axis=1)
df.columns[20:]<jupyter_output><empty_output><jupyter_text>RAM<jupyter_code>df[df['RAM記憶體'].isnull()]['Name']
name2ram = {'mto_m68_plus': 0.5,
            'apple_iphone_xr': 3,
            'apple_iphone_se_2020': 3,
            'apple_iphone_11': 4,
            'apple_iphone_11_pro': 4,
            'apple_iphone_12': 4,
            'apple_iphone_12_mini': 4,
            'apple_iphone_12_pro': 6,
            'apple_iphone_12_pro_max': 6,
            'apple_iphone_13': 4,
            'apple_iphone_13_mini': 4,
            'apple_iphone_13_pro': 6,
            'apple_iphone_13_pro_max': 6
           }
def handle_ram(x):
    ram = str(x['RAM記憶體'])
    
    if 'B' not in ram:
        return name2ram[x['Name']]
    else:
        if 'GB' in ram:
            return float(ram.replace('GB', ''))
        elif 'MB' in ram:
            return float(ram.replace('MB', ''))/1024
        
df['RAM記憶體'] = df.apply(handle_ram, axis=1)<jupyter_output><empty_output><jupyter_text>Other about memory<jupyter_code>df['UFS'] = df['儲存空間格式'].str.contains('UFS') == True
df['記憶卡'] = ~df['記憶卡'].isnull()
df = df.drop(['最大擴充儲存空間','記憶體格式','儲存空間格式'], axis=1)<jupyter_output><empty_output><jupyter_text>Camera<jupyter_code>df.columns
df = df.drop(['主相機感光元件', '主相機光圈F', '主相機等效焦距', '主相機LED補光燈', '主相機自動對焦',
              '第二主相機感光元件', '第二主相機光圈F', '第二主相機等效焦距',
             '第三主相機感光元件', '第三主相機光圈F','第三主相機等效焦距',
             '第四主相機感光元件', '第四主相機光圈F','第四主相機等效焦距',
              '前相機感光元件', '前相機光圈F', '前相機LED補光燈','前相機自動對焦',
              '第二前相機感光元件', '第二前相機光圈F'
             ], axis=1)
df = df.drop(['前相機等效焦距', '第三前相機光圈F', '第三前相機感光元件'], axis=1)
df.columns
df['主相機光學防手震'] = df['主相機光學防手震'] == 'Yes'
df['主相機UHD 4K錄影'] = df['主相機UHD 4K錄影'] == 'Yes'
df['前相機UHD 4K錄影'] = df['前相機UHD 4K錄影'] == 'Yes'
df['主相機8K錄影'] = df['主相機8K錄影'] == 'Yes'
def to_MP(x):
    x = str(x)
    if 'n' in x:
        return 0
    elif '萬畫素' in x:
        return float(x.replace('萬畫素', ''))/100
    elif '億畫素' in x:
        return float(x.replace('億畫素', ''))*100
    else:
        return float(x)/100
        
        
df['主相機畫素'] = df['主相機畫素'].apply(to_MP)
df['第二主相機畫素'] = df['第二主相機畫素'].apply(to_MP)
df['第三主相機畫素'] = df['第三主相機畫素'].apply(to_MP)
df['第四主相機畫素'] = df['第四主相機畫素'].apply(to_MP)
df['前相機畫素'] = df['前相機畫素'].apply(to_MP)
df['第二前相機畫素'] = df['第二前相機畫素'].apply(to_MP)
def calculate_cam_num(x):
    if x['第四主相機畫素'] != 0:
        return 4
    elif x['第三主相機畫素'] != 0:
        return 3
    elif x['第二主相機畫素'] != 0:
        return 2
    elif x['主相機畫素'] != 0:
        return 1
    else:
        return 0
df['cam_back_num'] = df.apply(calculate_cam_num, axis=1)
df = df.drop(['錄影格式'], axis=1)
df['RAW檔拍攝'] = df['RAW檔拍攝'] == 'Yes'<jupyter_output><empty_output><jupyter_text>Battery<jupyter_code>dict_charging = {
    'asus_zenfone_6_zs630kl': 18,
    'asus_zenfone_7_pro_zs671ks': 30,
    'asus_zenfone_7_zs670ks': 30,
    'blackshark_2': 27,
    'cat_s61': 18,
    'htc_desire_20plus': 18,
    'htc_desire_20_pro': 18,
    'huawei_mate_20_x_5g': 40,
    'lg_v60_thinq': 25,
    'lg_velvet': 27,
    'lg_wing': 25,
    'motorola_one_hyper': 45,
    'oppo_a91': 20,
    'sony_xperia_1_ii': 18,
    'sugar_t50': 15
}

def handle_charging(x):
    charging = str(x['快充功率'])
    if 'n' in charging and str(x['快充技術']) != 'nan':
        return dict_charging[x['Name']]
    elif 'n' in charging and x['Brand'] == 'apple':
        return 18
    elif 'n' in charging:
        return 10
    else:
        return float(charging.replace('W', ''))
        

df['快充功率'] = df.apply(handle_charging, axis=1)
df['無線充電'] = df['無線充電'] == 'Yes'
df['可替換電池'] = df['可替換電池'] == 'Yes'
df['無線反向充電'] = df['無線反向充電'] == 'Yes'
df = df.drop(['最大通話時間','快充技術'], axis=1)
df = df.drop(['最大待機時間'], axis=1)
df[df['電池容量'].isnull()]['Name']
dict_battery = {
    'apple_iphone_11': 3110,
    'apple_iphone_11_pro': 3046,
    'apple_iphone_12': 2815,
    'apple_iphone_12_mini': 2227,
    'apple_iphone_12_pro':  2815,
    'apple_iphone_12_pro_max': 3687,
    'apple_iphone_13': 3095,
    'apple_iphone_13_mini' : 2406,
    'apple_iphone_13_pro': 3095,
    'apple_iphone_13_pro_max': 4352,
    'apple_iphone_se_2020': 1821,
    'apple_iphone_xr': 2658
}

def handle_battery(x):
    b = str(x['電池容量'])
    if 'mAh' in b:
        return int(b.replace('mAh', ''))
    elif 'nan' in b:
        return dict_battery[x['Name']]
    else:
        return int(b)
df['電池容量'] = df.apply(handle_battery, axis=1)<jupyter_output><empty_output><jupyter_text>外觀<jupyter_code>df['glass'] = df['機身材質'].str.contains('玻璃') == True
df['plastic'] = df['機身材質'].str.contains('塑料') == True
df = df.drop(['機身材質'], axis=1)
df['摺疊螢幕'] = (df['裝置分類'].str.contains('摺疊螢幕') | df['裝置分類'].str.contains('疊螢幕'))
df = df.drop(['裝置分類'], axis=1)
def handle_whl(x):
    x['機身長度'] =  float(str(x['機身長度']).replace('mm', ''))
    x['機身寬度'] =  float(str(x['機身寬度']).replace('mm', ''))
    x['機身厚度'] =  float(str(x['機身厚度']).replace('mm', ''))
    
    return x

df = df.apply(handle_whl, axis=1)
df['副螢幕觸控'] = ((~df['副螢幕觸控'].isnull()) & df['副螢幕觸控'].str.contains('Yes'))
def handle_weight(x):
    if x['Name'] == 'koobee_s16':
        return 157
    else:
        return float(str(x['機身重量']).replace('g', ''))
df['機身重量'] = df.apply(handle_weight, axis=1)
df['機身顏色'] = df['機身顏色'].apply(lambda x: len(x.split(', ')))<jupyter_output><empty_output><jupyter_text>Sensor<jupyter_code>df.columns
df = df.drop(['陀螺儀', '加速度感應器', '指紋辨識器'], axis=1)<jupyter_output><empty_output><jupyter_text>Other<jupyter_code>df = df.drop(['喇叭', '紅外線','影片播放格式',
       '音樂播放器', '圖片支援格式',
             '實用工具', '時間顯示', '計步器', '內建觸控筆',
       '吊飾孔'], axis=1)
df['防水防塵等級'] = ~df['防水防塵等級'].isnull()
df['USB3'] = ((~df['傳輸埠'].isnull()) & df['傳輸埠'].str.contains('3'))
df = df.drop(['傳輸埠'], axis=1)
df['3.5mm耳機孔'] = ((~df['3.5mm耳機孔'].isnull()) & df['3.5mm耳機孔'].str.contains('Yes'))
df = df.drop(['麥克風'], axis=1)
df = df.drop(['副螢幕尺寸', '高度氣壓感測器', '副螢幕材質'], axis=1)
df = df.drop(['主螢幕佔比', '主螢幕耐用性'], axis=1)
df.to_csv('sogi_df.csv', index=False)
df = pd.read_csv('sogi_df.csv')
df
df.drop(['Name','副螢幕解析度'], axis=1).to_csv('sogi_mobile.csv', index=False)
set(df.columns)-set(['Price', 'ROM儲存空間', '主螢幕尺寸', '主相機畫素', '主相機光學防手震', '主相機UHD 4K錄影',
       '第二主相機畫素', '前相機畫素', '前相機UHD 4K錄影', 'NFC', '快充功率', '無線充電', 
        'Brand', '防水防塵等級','機身長度','機身重量',
       '機身寬度', '機身厚度','副螢幕觸控',
       '第三主相機畫素','RAM記憶體', '電池容量', '主相機8K錄影', 
       '記憶卡', 'RAW檔拍攝',  '可替換電池','USB3','3.5mm耳機孔',
       '無線反向充電', '第四主相機畫素',  '第二前相機畫素', 'soc_s', 'soc_m',
       'resolution_x', 'resolution_y', 'OLED', '90Hz', '120Hz', '144Hz',
       'Wifi5G', 'Wifi6', 'bt5.0', 'bt5.1', 'bt5.2', 'bt4.2', 'UFS','摺疊螢幕',
       'cam_back_num', 'glass', 'plastic'])<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup