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,210 points
348 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,300 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,210 points
161 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,140 points
8,795 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,520 points
30,096 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
235 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 757 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 1,577 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
9,664 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,620 points
3,626 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
129,377 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,300 points
211 views