How to extract all uppercase row to a new data frame

Question:

I have a pandas data frame which looks like this

Name Index1 Index2
AAA 67 70
Aaa 55 80
Abb 32 20
BBB 84 45
Baa 80 70
Bbb 13 40

where some rows have names with all uppercase and some with lowercase. How can i create another dataframe with only the uppercase rows

expected output will be :

Name Index1 Index2
AAA 67 70
BBB 84 45
Asked By: Irfan Khiari

||

Answers:

Use isupper from pandas:

df = df.loc[df["Name"].str.isupper(), :]
Answered By: Space Impact

same as above, without using loc

>>> df=pd.DataFrame(['AAA','Aaa','BBB','Bbb'],columns=['test'])
>>> df[df.test.str.isupper()==True]
  test
0  AAA
2  BBB
Answered By: Reda E.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.