An instance of the Series list set transformation

  • 2020-10-23 21:03:43
  • OfStack

The conversion method of set to list is as follows:

s = set('12342212') l = ['12342212']
print s # set(['1', '3', '2', '4']) s = set(l[0])
l = list(s) print s # set(['1', '3', '2', '4'])
l.sort() # sort m = ['11','22','33','44','11','22']
print l # ['1', '2', '3', '4'] print set(m) # set(['11', '33', '44', '22'])

It can be seen that set and lsit can be converted freely. When deleting multiple/massive repeating elements in list, they can be converted to set first, then returned to list and sorted (set is not sorted). This method is not only convenient but also efficient.

After converting to set, the intersection and union of two sets can be solved

As follows:


AA_16_only .  AA15_only  For the two  Series  Object: 


AA_16o_list =set(AA_16_only)
 AA15o_list = set(AA15_only)
 AA15_AA_16_only = AA15o_list.intersection(AA_16o_list)
 AA15_AA_16_only = pd.Series(list(AA15_AA_16_only))
 AA15_AA_16_only.to_csv('AA15_AA_16_only.csv')

Related articles: