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

change dataframe column type

>>> df.astype({'col1': 'int32'}).dtypes
col1    int32
col2    int64
dtype: object
Comment

pandas change dtype

# Individual  
df['a'] = df_test['a'].astype('float64')
df['b'] = df_test['b'].astype('int64')
# Batch
dtype_d = {"a": "float64", "b": "int64"} # dtype dictio
df = df.astype(dtype_d)
Comment

set column datatype pandas

df = pd.read_csv("weather.tsv", sep="	",  
                 dtype={'Day': str,'Wind':int64})
df.dtypes
Comment

pandas change column type

# select columns that need to be converted
cols = df.select_dtypes(include=['float64']).columns.to_list()
df = df.astype({col:int for col in cols})
Comment

how to change datatype of column in pandas

convert pandas datatype
Comment

dataframe change column types

df['current_anniversary_date'] = df['current_anniversary_date'].astype('datetime64[ns]')
Comment

PREVIOUS NEXT
Code Example
Python :: python dictionary get 
Python :: convert timedelta to int 
Python :: python aes encryption 
Python :: python datetime object 
Python :: pandas groupby mean round 
Python :: list from comma separated string python 
Python :: flask debugtoolbar 
Python :: requests 
Python :: what is the difference between python 2 and 3 
Python :: django install 
Python :: numpy random in python 
Python :: how to put a image in flask 
Python :: two dimensional array python 
Python :: how to code python 
Python :: subtract from dataframe column 
Python :: python generator 
Python :: how to get the remainder in python 
Python :: how to create an empty list of certain length in python 
Python :: c++ vs python 
Python :: ppcm python 
Python :: if main 
Python :: create or append dataframe to csv python 
Python :: PackagesNotFoundError: The following packages are not available from current channels: 
Python :: how to power in python 
Python :: python thread function 
Python :: how to write a script to display an image in python 
Python :: python print value and variable name 
Python :: how to create adjacency matrix from adjacency list in python 
Python :: list comprehension 
Python :: how to add a fuction in python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =