I have a dataframe with columns as mentioned
JavaScript
x
27
27
1
[-10800,
2
-9000,
3
-7200,
4
-5400,
5
-3600,
6
-1800,
7
0,
8
180,
9
300,
10
1200,
11
1800,
12
2400,
13
3600,
14
'-10800_R',
15
'-9000_R',
16
'-7200_R',
17
'-5400_R',
18
'-3600_R',
19
'-1800_R',
20
'0_R',
21
'180_R',
22
'300_R',
23
'1200_R',
24
'1800_R',
25
'2400_R',
26
'3600_R']
27
I want to only select the ‘_R’ columns
I am using list comprehension
JavaScript
1
2
1
[i for i in df.columns.to_list() if '_R' in i]
2
but i am getting the error of
JavaScript
1
2
1
TypeError: argument of type 'int' is not iterable
2
Is there another way to do it?
Advertisement
Answer
Building on @nacho’s comment:
JavaScript
1
2
1
[i for i in df.columns.to_list() if isinstance(i,str) and i.endswith("_R")]
2