File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Preparation/Join/Interval Join Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 44
44
45
45
df = sqldf (q , globals ())
46
46
47
+ def dedup_names (names ):
48
+ names = list (names )
49
+ counts = {}
47
50
51
+ for i , col in enumerate (names ):
52
+ cur_count = counts .get (col , 0 )
48
53
54
+ if cur_count > 0 :
55
+ names [i ] = '%s.%d' % (col , cur_count )
56
+
57
+ counts [col ] = cur_count + 1
58
+
59
+ return names
60
+
61
+
62
+ while sum (df .columns .duplicated (keep = False )) > 0 :
63
+ df .columns = dedup_names (df .columns )
49
64
50
- cols = pd .Series (df .columns )
51
- for dup in df .columns [df .columns .duplicated (keep = False )]:
52
- cols [df .columns .get_loc (dup )] = ([dup + '.' + str (d_idx )
53
- if d_idx != 0
54
- else dup
55
- for d_idx in range (df .columns .get_loc (dup ).sum ())]
56
- )
57
- df .columns = cols
58
65
59
66
output_data = df
60
67
You can’t perform that action at this time.
0 commit comments