Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

set dtype for multiple columns pandas

import pandas as pd

df = pd.DataFrame({'id':['a1', 'a2', 'a3', 'a4'],
  				   'A':['0', '1', '2', '3'],
                   'B':['1', '1', '1', '1'],
                   'C':['0', '1', '1', '0']})

df[['A', 'B', 'C']] = df[['A', 'B', 'C']].apply(pd.to_numeric, axis = 1)
Comment

pandas change multiple column types

#Two ways to do this
df[['parks', 'playgrounds', 'sports']].apply(lambda x: x.astype('category'))

cols = ['parks', 'playgrounds', 'sports', 'roading']:
public[cols] = public[cols].astype('category')
Comment

PREVIOUS NEXT
Code Example
Python :: python regex cheat sheet 
Python :: python check folder exists 
Python :: change selected option optionmenu tkinter 
Python :: iterate over list and select 2 values together python 
Python :: merge two df 
Python :: pip install django rest framework 
Python :: tkinter button command with arguments 
Python :: time now random seed python 
Python :: selenium chromeoptions user agent 
Python :: lista to txt python 
Python :: python import beautifulsoup 
Python :: python average 
Python :: How to return images in flask response? 
Python :: 3d array in numpy 
Python :: how to add color to python text 
Python :: python randomize a dataframe pandas 
Python :: converting jupyter notebook files to python 
Python :: find average of list python 
Python :: case statement in querset django 
Python :: what is pypy 
Python :: numpy matrix 
Python :: joblib 
Python :: jupyter upload folder 
Python :: python regex get all matches 
Python :: python set intersection 
Python :: networkx path between two nodes 
Python :: sum of positive numbers in array with negative python 
Python :: pandas dataframe delete column 
Python :: install flask on linux mint for python3 
Python :: python use variable in regex expression 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =