Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to convert Float to Int in Python?
Next article icon

How to Convert float64 Columns to int64 in Pandas?

Last Updated : 11 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

float64 represents a floating-point number with double precision and int64 represents a 64-bit integer number. In this article, we will learn to Convert float64 Columns to int64 in Pandas using different methods

Convert float64 Columns to int64 in Pandas DataFrame

To transform a Pandas column to an integer type within a DataFrame, you have the option to utilize either the DataFrame's astype(int) or the apply() method. This enables the conversion of a column from various data types such as float or string to an integer type, specifically int64 or int32.

1. Using astype() Method

We can use astype() method in Python to convert float64 Columns to int64 in Pandas.

In this example, we create a data frame with floating values and then we convert floating values into integer values using astype() function, This function converts the datatype to another datatype.

Python
import pandas as pd  # Create a sample DataFrame data = {'A': [1.0, 2.0, 3.0],         'B': [4.0, 5.0, 6.0]} df = pd.DataFrame(data)  print("Before converting") print(df.dtypes)  # Convert float64 columns to int64 using astype() df['A'] = df['A'].astype('int64') df['B'] = df['B'].astype('int64')  print("\nAfter converting") # Check the data types of columns print(df.dtypes)   

Output:

Before converting
A float64
B float64
dtype: object
After converting
A int64
B int64
dtype: object

As you can observe the float64 values in the dataset are converted to int64 datatype.

2. Using apply() and astype() function

We can use the apply() method along with the astype(int) function to convert the columns of the Pandas DataFrame to integers.

Python
import pandas as pd data = {'A': [1.0, 2.4, 3.0],         'B': [4.0, 5.0, 6.5]}  print("Before converting") print(df.dtypes) # Use apply method to convert Pandas columns to int df_int = df.apply(lambda column: column.astype(int))  # Check the data types of columns print("\nAfter converting") print(df_int.dtypes) 

Output:

Before converting
A float64
B float64
dtype: object
After converting
A int64
B int64
dtype: object

As you can observe the float64 values in the dataset are converted to int64 datatype.

Conclusion

In conclusion,we can Convert float64 Columns to int64 in Pandas within few clicks.


Next Article
How to convert Float to Int in Python?

H

hanishj
Improve
Article Tags :
  • Pandas

Similar Reads

  • How to Convert Index to Column in Pandas Dataframe?
    Pandas is a powerful tool which is used for data analysis and is built on top of the python library. The Pandas library enables users to create and manipulate dataframes (Tables of data) and time series effectively and efficiently. These dataframes can be used for training and testing machine learni
    2 min read
  • How To Convert Pandas Column To List
    One of the common tasks when working with a DataFrame in Pandas is converting a column to a list. In this article we will learn how to convert a Pandas column to a list using various methods. 1. Using tolist()One can convert a pandas column to a list using tolist() function which works on the Pandas
    4 min read
  • How to convert Float to Int in Python?
    In Python, you can convert a float to an integer using type conversion. This process changes the data type of a value However, such conversions may be lossy, as the decimal part is often discarded. For example: Converting 2.0 (float) to 2 (int) is safe because here, no data is lost.But converting 3.
    5 min read
  • How to Convert Pandas Columns to String
    Converting columns to strings allows easier manipulation when performing string operations such as pattern matching, formatting or concatenation. Pandas provides multiple ways to achieve this conversion and choosing the best method can depend on factors like the size of your dataset and the specific
    3 min read
  • Convert a Dataframe Column to Integer in Pandas
    Converting DataFrame columns to the correct data type is important especially when numeric values are mistakenly stored as strings. Let's learn how to efficiently convert a column to an integer in a Pandas DataFrame Convert DataFrame Column to Integer - using astype() Methodastype() method is simple
    3 min read
  • Convert the data type of Pandas column to int
    In this article, we are going to see how to convert a Pandas column to int. Once a pandas.DataFrame is created using external data, systematically numeric columns are taken to as data type objects instead of int or float, creating numeric tasks not possible. We will pass any Python, Numpy, or Pandas
    2 min read
  • How to Drop Index Column in Pandas?
    When working with Pandas DataFrames, it's common to reset or remove custom indexing, especially after filtering or modifying rows. Dropping the index is useful when: We no longer need a custom index.We want to restore default integer indexing (0, 1, 2, ...).We're preparing data for exports or transf
    2 min read
  • How to convert pandas DataFrame into JSON in Python?
    JSON (JavaScript Object Notation) is a lightweight, easily readable format widely used for data interchange between applications, making it ideal for sharing data across different systems. With Pandas, converting a DataFrame into JSON is simple and efficient using the to_json() function. This articl
    7 min read
  • How to Convert Integer to Datetime in Pandas DataFrame?
    Let's discuss how to convert an Integer to Datetime in it. Now to convert Integers to Datetime in Pandas DataFrame. Syntax of  pd.to_datetimedf['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)Create the DataFrame to Convert Integer to Datetime in Pandas Check
    2 min read
  • Convert Pandas Dataframe Column To Float
    Converting columns to floats in Pandas DataFrame is a very crucial step for data analysis. Converting columns to float values can help you perform various arithmetic operations and plot graphs. In this article, we’ll look at different ways to convert a column to a float in DataFrame. Using DataFrame
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences