Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change dataframe column type

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

pandas change column 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 type of column pandas

df.astype(int)
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 :: waiting in python. time , sleep 
Python :: compare multiple columns in pandas 
Python :: python call function in class 
Python :: Check np.nan value 
Python :: concatenation of array in python 
Python :: swap 2 no in one line python 
Python :: If elif else 
Python :: save pillow image to database django 
Python :: pytorch cuda tensor in module 
Python :: python To find the sum of all the elements in a list. 
Python :: while loops python 
Python :: models in django 
Python :: installing python3.9 on linux mint 20 
Python :: django abstractuser 
Python :: matplotlib axis labels 
Python :: composition in python 
Python :: python telegram bot login 
Python :: discord.py permissions 
Python :: wifite2 
Python :: binary tree in python 
Python :: read csv python 
Python :: missing data in python 
Python :: boto3.client python 
Python :: matrix diagonal sum leetcode in Python 
Python :: django change settings at runtime 
Python :: python tkinter checkbox default value 
Python :: python how to add a string to a list in the middle 
Python :: keras conv2d 
Python :: python -c 
Python :: continue and break in python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =