सस्ता, तेज़, और मुहावरेदार: str.contains
पांडा के हाल के संस्करणों में, आप अनुक्रमणिका और स्तंभों पर स्ट्रिंग विधियों का उपयोग कर सकते हैं। यहाँ, str.startswithएक अच्छा फिट की तरह लगता है।
दिए गए विकल्प के साथ शुरू होने वाले सभी स्तंभों को हटाने के लिए:
df.columns.str.startswith('Test')
# array([ True, False, False, False])
df.loc[:,~df.columns.str.startswith('Test')]
toto test2 riri
0 x x x
1 x x x
केस-असंवेदनशील मिलान के लिए, आप str.containsSOL एंकर के साथ रेगेक्स-आधारित मिलान का उपयोग कर सकते हैं :
df.columns.str.contains('^test', case=False)
# array([ True, False, True, False])
df.loc[:,~df.columns.str.contains('^test', case=False)]
toto riri
0 x x
1 x x
यदि मिश्रित प्रकार एक संभावना है, तो भी निर्दिष्ट करें na=False।