I have a dataframe in which I have 2 records that are with few values, I wanted to replace those records with others with more values, make a copy. Does anyone know how to do this on pandas or vaex?
wanted to replace the values 148 for example with the values 140 Someone help?
edit: my dataframe is this
I would like to replace all values of day_of_week = 148 with values of day_of_week = 140 because (day_of_week = 148) has 1000 records and (day_of_week = 140) has 200000 records
I want to copy all lines day_of_year == 140 and replace for all lines that are day_of_year == 148
If I understand you correctly, this should be straightforward in vaex:
df['new_col'] = df.func.where(df.day_of_week==148, 140, df.day_of_week)
In vaex the new column will be virtual, ie not take any memory. So it does not matter if you overwrite your existing one, or keep a separate one with the mapping (maybe better to keep a separate one, in case you need to debug your process later on).
I think something similar can be done with pandas, using numpy.where
as it was already commented before me.
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.