python - Unsure of data type returned nparray operations -
i've written function similar this:
def my_function(my_series): return my_series.mean() * 500
i passing in pandas series object my_series. compute , print , following:
dtype: float64 234.43646
what returning here? have cast float() before can use it. worse when store many of these in series, end series of of information.
this trivial i've been stuck on bit now. guys!
edit: here's rest , why it's issue. don't understand why this.
new_array = [] yr in year_list: new_array.append(my_function(df.loc[df.index.year == yr, ['cola']])) df['new_col'] = new_array
maybe problem in assignment here new series in existing dataframe. each entry in series isn't number, it's full dtype: float 64 , number.
if instead change function above
return float(my_series.mean() * 500)
then when print result float number, without info.
edit #2 (sorry edits, last one)
print(df['new_col'])
yields this:
new_col 2000 new_col 0.2343 dtype:float64 2001 new_col 0.2343 dtype:float64 2002 new_col 325 dtype:float64 2003 new_col 123 dtype:float64
instead of just:
new_col 2000 0.2343 2001 0.2343 2002 325 2003 123
wiki
Comments
Post a Comment