Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert data type of a column in pandas

# You can use "astype" method
# suppose you want to correct your "sales" column data type
df['sales'] = df['sales'].astype('float64')
Comment

convert pandas column type

# convert all columns of DataFrame
df = df.apply(pd.to_numeric) # convert all columns of DataFrame

# convert just columns "a" and "b"
df[["a", "b"]] = df[["a", "b"]].apply(pd.to_numeric)
Comment

PREVIOUS NEXT
Code Example
Python :: export csv 
Python :: matplotlib plot 2d point 
Python :: python check if string is number reges 
Python :: pygame how to get surface lenght 
Python :: Import CSV Files into R Using fread() method 
Python :: await async function from non async python 
Python :: create models in django 
Python :: python how to change an element in a multi dimensional list 
Python :: python multithreading tutorials 
Python :: python list abstraction 
Python :: show image python 
Python :: pytest run only failed test 
Python :: public in python 
Python :: how to 404 custom page not found in django 
Python :: comparing two dataframe columns 
Python :: Get last “column” after .str.split() operation on column in pandas DataFrame 
Python :: python create environment linux 
Python :: remove special characters from string python 
Python :: How to return images in flask response? 
Python :: python import worldcloud 
Python :: how to add column to np array 
Python :: python datetime weekday 
Python :: flask read form data 
Python :: pyautogui color 
Python :: runtime.txt heroku python 
Python :: df index start from 1 
Python :: python find number of occurrences in list 
Python :: python iterate through dictionary 
Python :: how to print python 
Python :: concatenate data vertically python 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =