简体   繁体   中英

Ipyton notebook/jupyter

I'm still relatively new to ipython and am trying to do some data transformation. I am using the data from an email blast in order to determine the effectiveness of the action and one of the factors that I would like to use is determining the amount of dollars spent by each customer after the blast. As you can guess, there are a lot of "0"s in there and it skews this particular portion of the analysis.

My question is, how do I just drop the 0 values in this column while leaving the customer information for those who have spent money intact. I've been trying to experiment with making 0 a null value, but I don't know the right sequence of code. "spend" is the name of the column that I'm attempting to change

dfspend = df1.replace({'spend': 0}, {'spend': isnull})

This is a rough idea of what I've been trying to do, except that the isnull is invalid.

Try this:

import numpy as np
df1.ix[df1.spend == 0, 'spend'] = np.nan

I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM