献丑
group_by有个缺点是相同的内容必须是连续的或者说是排过序的 |
用pandas 内建itertools里的groupby也可以,自己去研究一下 import pandas as pd a=["SHFE.al", "SHFE.cu", "SHFE.zn", "CZCE.SR","CZCE.CF","CZCE.CY","CZCE.ZC", "DCE.m","DCE.y","DCE.a","DCE.b","DCE.p", "CFFEX.IF","CFFEX.IH","CFFEX.IC","CFFEX.TS", "INE.sc"] df=pd.DataFrame(a,columns=['a']) df['temp']=df['a'].apply(lambda x: x.split('.')[0]) grouped=df.groupby('temp')['a'] for i,data in grouped: print(list(data)) |
|