python - AttributeError: 'DataFrame' object has no attribute 'ravel' -
i trying test panda program works fine on other system.
import pandas pd import numpy np pandas import series, dataframe ds1 = pd.read_table('data.txt', sep=' ', header=none) ds2 = pd.read_table('dataset.txt', header=none, sep=' ') out = ds1.copy() _,c = np.where(ds1.ravel()[:,none] == ds2[:,0]) newvals = ds2[c,1] # valid positions in output array changed valid = np.in1d(ds1.ravel(),ds2[:,0]) # make changes desired output out.ravel()[valid] = newvals print out
when tried gives,
_,c = np.where(ds1.ravel()[:,none] == ds2[:,0]) file "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 1947, in __getattr__ (type(self).__name__, name)) attributeerror: 'dataframe' object has no attribute 'ravel'
update
sample raw data:
ds1 = pd.read_table('https://gist.githubusercontent.com/karimkhanp/9527bad750fbe75e072c/raw/ds1', sep=' ', header=none) ds2 = pd.read_table('https://gist.githubusercontent.com/karimkhanp/1692f1f76718c35e939f/raw/6f6b348ab0879b702e1c3c5e362e9d2062e9e9bc/ds2', header=none, sep=' ')
well error pretty clear, want access numpy values
attribute:
_,c = np.where(ds1.values.ravel()[:,none] == ds2[:,0])
Comments
Post a Comment