简体   繁体   中英

how to replace all values in pandas data frame

I need to replace all values of pandas dataframe in a fast way.

data = pd.read_csv("data.txt", sep="\s*,", header=None)
cross_tab1 = pd.crosstab(data[0], data[1], rownames=['data0'], colnames=['data1'])

after that I want to take all values from data frame and add noise to all. I need something to make this possible data.values = data.values + np.random.normal(0, 2.0) Can you please help me?

if you want a line as close as possible to data.values = data.values + np.random.normal(0, 2.0) then you might try something like:

data.update(data.values + np.random.normal(0, 2.0))

you could also look at apply, applymap, or transform

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