विशिष्ट डेटाटाइप वाले कॉलम चुनने के लिए, select_dtypes() मेथड और include पैरामीटर का उपयोग करें। सबसे पहले, 2 कॉलम वाला डेटाफ्रेम बनाएं –
dataFrame = pd.DataFrame(
{
"Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],
"Roll Number": [5, 10, 3, 8, 2, 9, 6]
}
)
अब, अपने संबंधित विशिष्ट डेटाटाइप के साथ 2 कॉलम चुनें –
column1 = dataFrame.select_dtypes(include=['object']).columns column2 = dataFrame.select_dtypes(include=['int64']).columns
उदाहरण
निम्न कोड है –
import pandas as pd
# डेटाफ्रेम बनाएं
dataFrame = pd.DataFrame(
{
"Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],
"Roll Number": [5, 10, 3, 8, 2, 9, 6]
}
)
print "DataFrame ...\n", dataFrame
print "\nInfo of the entire dataframe:\n"
# विवरण प्राप्त करें
print(dataFrame.info())
# विशिष्ट डेटाटाइप वाले कॉलम चुनें
column1 = dataFrame.select_dtypes(include=['object']).columns
column2 = dataFrame.select_dtypes(include=['int64']).columns
print "Column 1 with object type = ", column1
print "Column 2 with int64 type = ", column2
आउटपुट
यह निम्न आउटपुट उत्पन्न करेगा –
DataFrame ... Roll Number Student 0 5 Jack 1 10 Robin 2 3 Ted 3 8 Marc 4 2 Scarlett 5 9 Kat 6 6 John Info of the entire dataframe:RangeIndex: 7 entries, 0 to 6 Data columns (total 2 columns): Roll Number 7 non-null int64 Student 7 non-null object dtypes: int64(1), object(1) memory usage: 184.0+ bytes None Column 1 with object type = Index([u'Student'], dtype='object') Column 2 with int64 type = Index([u'Roll Number'], dtype='object')