Forums

DataFrame' object has no attribute 'sample'

DataFrame' object has no attribute 'sample'

df1 = df.sample(frac=1)

Below code works in newer version 0.16

df1 = df.sample(frac=1)

#works in older version 0.14
num = len(df)
df1 = df.loc[random.sample(list(df.index),num)]

This is pandas related. See http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sample.html

Current version is 0.20.1. Be nice to have pandas and dependencies updated. Ta.

how can i upgrade pandas on pythonanywhere?? bcoz current version as shown is 0.14

There are 2 solutions.

  1. Use virtualenv (which is what I do) and then pip install whatever you like to a fresh python install.

  2. pip install --user in the PA environment. This installs the package in the user site, as opposed to the system python site (to which you don't have access).

+1 to what @billyquith says. We will be releasing a new system image with updated packages relatively soon, but not in tomorrow's system update.