Skip to content

Commit ce626c9

Browse files
To replace single quotes with double quotes.
Added code containing script to convert list of columns with single quotes to double quotes.
1 parent 407ceca commit ce626c9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'''
2+
3+
Here we are trying to convert the list element stored in single quotes with
4+
that to stored in double quotes. Also the output is string as in list elements are by default enclosed in single quotes.
5+
6+
'''
7+
8+
# Either define list of columns or directly store from df.columns
9+
10+
# List df_columns contains the columns of the dataframe
11+
df_columns = ['Column 1','Column 2','Column 3','Column 4','Column 5','Column 6']
12+
13+
# Empty string to Store Result
14+
df_columns_string = ''
15+
16+
17+
# Traversing elements and adding double quotes
18+
for i in df_columns:
19+
20+
# For the last element we do not need to append comma
21+
if i == df_columns[-1]:
22+
23+
# Here element is appended with double quotes
24+
ele = '"' + i + '"'
25+
26+
# Added in final list
27+
# Not Added comma as it is the last element
28+
df_columns_string = df_columns_string + ele
29+
30+
else:
31+
# Here element is appended with double quotes
32+
ele = '"' + i + '"'
33+
34+
# Added in final list
35+
# Added comma to distinguish next element
36+
df_columns_string = df_columns_string + ele + ',' + ' '
37+
38+
39+
40+
# Printing Final Output
41+
# This can directly be copied in grafana variable
42+
print("Columns after converting to double quotes string is:\n")
43+
print(df_columns_string)

0 commit comments

Comments
 (0)