python - Multiplication on slice of pandas dataframe -
i have dataframe this:
year a_annex arnston bachelor berg 1955 1.625 0.940 nan nan 1956 1.219 1.018 nan nan 1957 2.090 1.20 nan 1.190 1958 0.950 1.345 nan 1.090
and want multiply in [1:,1:]
.404
the code trying is:
df=pd.read_csv(r'h:\sheyenne\grazing records\master_amu_complete.csv') hectare=0.404 df=df.iloc[1:,1:] df=df*hectare
but returns:
typeerror: not operate 0.404686 block values can't multiply sequence non-int of type 'float'
printing df.info()
says after slice non-null object if helps.
yes, problematic value. can find these problematic values function (thanks ajcr):
df = df.convert_objects(convert_numeric=true)
first nan
converted 0
, apply function above , return nan instead of problematic values. have find rows nan values , return subset of original df
.
print df year a_annex arnston bachelor berg 0 1955 1.625 0.940 nan nan 1 1956 1.219 1.018 nan nan 2 1957 2.090 1.20a nan 1.19 3 1958 0.950 1.345a nan 1.09 test = df.fillna(0) test = test.convert_objects(convert_numeric=true) year a_annex arnston bachelor berg 0 1955 1.625 0.940 0 0.00 1 1956 1.219 1.018 0 0.00 2 1957 2.090 nan 0 1.19 3 1958 0.950 nan 0 1.09 test = df[test.isnull().any(axis=1)] year a_annex arnston bachelor berg 2 1957 2.09 1.20a nan 1.19 3 1958 0.95 1.345a nan 1.09 hectare=0.404 df=df.iloc[1:,1:] df=df*hectare print df
Comments
Post a Comment