- Python字典鍵值互換
1. new_dict={key:value for v,k in old_dict.items()}
2. new_dict=dict(zip(old_dict.values(),d1.keys()))
- 輸出固定長度字符串,前面用0填充
a='1234'
b=a.zfill(6)
print(b)
# b='001234'
- Pandas使用concat合并數(shù)據(jù)后groupby有"主鍵"重復(fù)
從多個系統(tǒng)獲取到的 [月份,銷量] 使用concat合并后匯總
由于月份字段一邊是"201901" 另一邊是201901
數(shù)值類型不同,pandas執(zhí)行g(shù)roupby會保留兩條
concat之前要檢查確保數(shù)據(jù)類型一致
- Pandas應(yīng)用groupby 將目標(biāo)列的內(nèi)容用逗號分隔拼接起來
基本
df_new = df.groupby('fd').agg({'value': lambda x: ','.join(x)}).reset_index()
對拼接內(nèi)容去重
df_new = df.groupby('fd').agg({'value': lambda x: '/'.join(str(xx) for xx in list(set(x)))}).reset_index()
遇到了慢慢加。。。