Python & Pandas: How To Return A Copy Of A Dataframe?
Here is the problem. I use a function to return a randomized data, data1 = [3,5,7,3,2,6,1,6,7,8] data2 = [1,5,2,1,6,4,3,2,7,8] df = pd.DataFrame(data1, columns = ['c1']) df['c2']
Solution 1:
Use DataFrame.assign()
:
def randomize_data(df):
return df.assign(c1=df.c1 + np.random.uniform(0, 1, df.shape[0]))
Solution 2:
I think you are right, and DataFrame.copy() have an optional argument 'deep'. You can find details in http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.copy.html
Post a Comment for "Python & Pandas: How To Return A Copy Of A Dataframe?"