Guest User

Untitled

a guest
Feb 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. df1 = pd.DataFrame({'Information1' : [19, 'game. tennis','Prof. HANA
  5. YAMADA', 'Canada.'],
  6. 'Information2' : ['books', 24, 'Shopping.','A. ELIZABETH
  7. JONES.'],
  8. 'Information3' : ['Mr. ADAMS', 'Italy', 'Japan', 23],
  9. 'Information4' : ['Australia', 'MARCO', 25, 'movies']},
  10. index = {'Person1','Person2','Person3', 'Person4'}
  11. )
  12.  
  13. Information1 Information2 Information3 Information4
  14. Person1 19 books Mr. ADAMS Australia
  15. Person2 game. tennis 24 Italy MARCO
  16. Person3 Prof. HANA YAMADA Shopping. Japan 25
  17. Person4 Canada. A. ELIZABETH JONES. 23 movies
  18.  
  19. Name
  20. Person1 ADAMS
  21. Person2 MARCO
  22. Person3 HANA YAMADA
  23. Person4 A. ELIZABETH JONES.
  24.  
  25. Name = []
  26. for row in df1.itertuples():
  27. for item in row:
  28. if hasattr(item, "isupper") and item.isupper():
  29. Name.append(item)
  30. break
  31. else:
  32. Name.append(None)
  33. df1["Name"] = Name
  34. df1 =df1.drop(['Information1','Information2','Information3','Information4'],
  35. axis=1)
  36.  
  37. Name
  38. Person1 None
  39. Person2 MARCO
  40. Person3 None
  41. Person4 A. ELIZABETH JONES.
Add Comment
Please, Sign In to add comment