python - Is it possible to run replace on a list/subset of columns in a dataFrame? -


for example:

dataset['column_1'].replace(['(null)'],['0'],inplace=true) 

replaces of 'error' strings in column one. if want few specific columns right i'm going:

dataset['column_1'].replace(['(null)'],['0'],inplace=true) dataset['column_5'].replace(['(null)'],['0'],inplace=true) dataset['column_7'].replace(['(null)'],['0'],inplace=true) 

is there way combine , run same replace on list of column names?

i have tried doing this:

names = ['column_1','column_2','column_3','column_4','column_5','column_6','column_7'] dataset = pandas.read_csv('allvalues.csv', names=names) dataset[['column_1','column_3','column_4','column_7']].replace(['(null)'],[0],regex=true,inplace=true) 

but columns still being printed afterwards '(null)' string values.

you can use dataframe.replace() instead of series.replace():

dataset[['column_1','column_5','column_7']].replace(['error'],['0'],                                                    regex=true, inplace=true) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -