ในการรับประเภทข้อมูลของคอลัมน์ ให้ใช้เมธอด info() ให้เรานำเข้าไลบรารีที่จำเป็นก่อน -
import pandas as pd
สร้าง DataFrame โดยมี 2 คอลัมน์ที่มีประเภทข้อมูลต่างกัน -
dataFrame = pd.DataFrame(
{
"Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],"Roll Number": [ 5, 10, 3, 8, 2, 9, 6]
}
) รับข้อมูลที่สมบูรณ์เกี่ยวกับประเภทข้อมูล -
dataFrame.info()
ตัวอย่าง
ต่อไปนี้เป็นรหัสที่สมบูรณ์ -
import pandas as pd
# Create DataFrame
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 and the datatypes of the columns in the dataframe:\n"
# get the datatypes info
print(dataFrame.info()) ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
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 and the datatypes of the columns in the dataframe: <class 'pandas.core.frame.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