溫馨提示×

jupyter如何查看數(shù)據(jù)類型

小億
164
2024-05-23 16:15:08
欄目: 編程語言

在jupyter notebook中,可以使用type()函數(shù)來查看變量的數(shù)據(jù)類型。例如:

x = 5
print(type(x))  # 輸出:<class 'int'>

y = "hello"
print(type(y))  # 輸出:<class 'str'>

z = [1, 2, 3]
print(type(z))  # 輸出:<class 'list'>

另外,使用df.dtypes屬性可以查看DataFrame中每列的數(shù)據(jù)類型。例如:

import pandas as pd

df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'c']})
print(df.dtypes)

這樣就可以看到DataFrame中每列的數(shù)據(jù)類型。

0