How to change data types in Pandas DataFrame

0 votes

Hi Guys,

I have one DataFrame in Pandas. It is in the int64 format. I want to change the data type of this DataFrame. How can I do this?

Jun 23, 2020 in Python by akhtar
• 38,260 points
1,157 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use astype function to change data types in Pandas. You can go through the below-given example.

data = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=data)
df.dtypes
col1    int64
col2    int64
dtype: object
df.astype('int32').dtypes
col1    int32
col2    int32
dtype: object

I hope this will help you.

answered Jun 23, 2020 by MD
• 95,460 points

Related Questions In Python

0 votes
1 answer

How to append new data in pandas DataFrame?

Hi@MD, You can use the append function to ...READ MORE

answered Jun 23, 2020 in Python by akhtar
• 38,260 points
739 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,020 points
11,722 views
0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,560 points
34,451 views
0 votes
1 answer

How can I change the data type to string in Python?

You can use str(variablename) This is called conversion ...READ MORE

answered Dec 18, 2018 in Python by Shuvodip
992 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by MD 2,060 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by Gitika 2,861 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
13,743 views
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,660 points
4,577 views
+1 vote
3 answers

How to change/update cell value in Python Pandas dataframe?

You can use the at() method to ...READ MORE

answered Apr 8, 2019 in Python by Kunal
147,371 views
+1 vote
1 answer

How to change the order of DataFrame columns in pandas?

Hi@akhtar, You can rearrange a DataFrame object by ...READ MORE

answered Oct 20, 2020 in Python by MD
• 95,460 points
860 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP