I have a database which has 7 columns and 35 rows. How do I only display only 'n' number of columns at once? Say I want to just see the columns 1,2, and 5. Is there any way to do that using the column names and/or column number? I was using this print(df['Offenders = Neighbours','Offenders Known'])
, where 'Offenders=Neighbours' and 'Offenders Known' were two of the column names. It worked when there was just one column name but not for more than one. Sounds like a very basic question but I'm new to Pandas so any help would be appreciated
Asked
Active
Viewed 3,871 times
0

Abhishek
- 553
- 2
- 9
- 26
-
2`df[[Neighbours','Offenders Known']]` ?? – anky Mar 23 '19 at 14:45
-
1You can also use `.iloc` if you want to reference using column numbers instead of names, eg: `df.iloc[:, [0, 1, 4]]` – Jon Clements Mar 23 '19 at 14:48
-
Solved the problem. Thank you – Abhishek Mar 23 '19 at 14:48
-
1@Abhishek you might also want to consider trying: `df.filter(like='Offenders')` if there's a common pattern in the names... – Jon Clements Mar 23 '19 at 14:49
-
Do you mean column names? Or the values under the column? Because the values under the column are int since they're a count of the number of offenders in a certain area @JonClements – Abhishek Mar 23 '19 at 14:51
-
1Column names @Abhishek – Jon Clements Mar 23 '19 at 14:52
-
Amazing @JonClements. Just checked and works like a dream – Abhishek Mar 23 '19 at 14:57