Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can anyone tell me how to find data type in Python?

1 Answer

0 votes
by (119k points)

In Python, you can use type () in-built method to find the data type of that variable as follows:

score = 95

type(score)

output:

int

You can use .dtypes to find the data types of all the columns of a data frame as follows:

import pandas as pd

#creating a dataframe

items = [['Phone', 10000], ['Telivision', 25000], ['Laptop', 48000]]

df = pd.DataFrame(items, columns=['Item', 'Cost'], dtype=float)

#to find datatypes of all columns

df.dtypes

 output:

Item     object

Cost    float64

dtype: object

I recommend this Python Tutorial by Intellipaat to learn more about Datatypes in Python.

Also, watch this video on Python data types:

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 3, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Sep 3, 2020 in Python by ashely (50.2k points)
0 votes
1 answer

Browse Categories

...