केवल कैपिटल शब्द प्राप्त करने के लिए, हम रेगेक्स का उपयोग कर रहे हैं। re मॉड्यूल का उपयोग यहां किया गया है और इम्पोर्ट किया गया है। सभी लाइब्रेरी इम्पोर्ट करें –
import re import pandas as pd
डेटाफ्रेम बनाएं –
data = [['computer', 'mobile phone', 'ELECTRONICS', 'electronics'],['KEYBOARD', 'charger', 'SMARTTV', 'camera']] dataFrame = pd.DataFrame(data)
अब, कैपिटल शब्द निकालें –
for i in range(dataFrame.shape[1]):
for ele in dataFrame[i]:
if bool(re.match(r'\w*[A-Z]\w*', str(ele))):
print(ele)
उदाहरण
निम्न कोड है –
import re
import pandas as pd
# डेटाफ्रेम बनाएं
data = [['computer', 'mobile phone', 'ELECTRONICS', 'electronics'],['KEYBOARD', 'charger', 'SMARTTV', 'camera']]
dataFrame = pd.DataFrame(data)
# डेटाफ्रेम
print "Dataframe...\n", dataFrame
print "\nDisplaying only capital words...\n"
# कैपिटल शब्द निकालना
for i in range(dataFrame.shape[1]):
for ele in dataFrame[i]:
if bool(re.match(r'\w*[A-Z]\w*', str(ele))):
print(ele)
आउटपुट
यह निम्न आउटपुट उत्पन्न करेगा –
Dataframe... 0 1 2 3 0 computer mobile phone ELECTRONICS electronics 1 KEYBOARD charger SMARTTV camera Displaying only capital words... KEYBOARD ELECTRONICS SMARTTV