如何删除重复项,但保持关系。
就我而言,我在股票中有重复项,但在代码中没有重复项。
import pandas as pd
df = pd.DataFrame({'Code' : ['NSPWRUTBL1','NSPWRUTBL2','NSPWRUTBL3','NSPWRUTPK1','NSPWRUTPK2','NSPWRUTPK3'],
'Stock' : ['890353-336','890353-336','890353-336','890353-850','890353-850','890353-850']})
print(df.drop_duplicates())
实际输出:
Code Stock
0 NSPWRUTBL1 890353-336
1 NSPWRUTBL2 890353-336
2 NSPWRUTBL3 890353-336
3 NSPWRUTPK1 890353-850
4 NSPWRUTPK2 890353-850
5 NSPWRUTPK3 890353-850
我希望得到一个实例,例如:
0 NSPWRUTBL1 890353-336
3 NSPWRUTPK1 890353-850