You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def Func_df(df):
cases_list = [monthly_pattern_check(x,y) for x,y in zip(df[[0]].values,df[[1]].values)]
print collections.Counter(cases_list)
return dict(collections.Counter(cases_list))
def monthly_pattern_check(r,c):
if r > c > 0:
return 'A'
elif c > r > 0 :
return 'B'
elif r > 0 > c:
return 'C'
elif r == 0 and c > 0:
return 'D'
elif r < c < 0:
return '-A'
elif c < r < 0:
return '-B'
elif r < 0 < c:
return '-C'
elif r == 0 and c < 0:
return '-D'
Expected Output
pattern_tmp1 should be assigned to the the [0] index value of Counter({'-B': 1})
output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 13.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
@algotr8der You should investigate how it comes that you end up with a series name that is a dict, and then try to see how you can achieve what you want using a regular column name.
Code Sample, a copy-pastable example if possible
This is the following SO issue: http://stackoverflow.com/questions/37195658/pandas-typeerror-series-name-must-be-a-hashable-type
Call to Func_df(df):
pattern_tmp1 = grouped[['sprd1','cost1']].apply(Func_df)[0]
Input df to Func_df(df):
sprd1 cost1
date
2016-01-31 -19.02 -436.31
def Func_df(df):
cases_list = [monthly_pattern_check(x,y) for x,y in zip(df[[0]].values,df[[1]].values)]
print collections.Counter(cases_list)
return dict(collections.Counter(cases_list))
def monthly_pattern_check(r,c):
if r > c > 0:
return 'A'
elif c > r > 0 :
return 'B'
elif r > 0 > c:
return 'C'
elif r == 0 and c > 0:
return 'D'
elif r < c < 0:
return '-A'
elif c < r < 0:
return '-B'
elif r < 0 < c:
return '-C'
elif r == 0 and c < 0:
return '-D'
Expected Output
pattern_tmp1 should be assigned to the the [0] index value of Counter({'-B': 1})
output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 13.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.1
setuptools: 20.7.0
Cython: 0.22.1
numpy: 1.10.4
scipy: 0.16.0
statsmodels: None
xarray: None
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.4
blosc: None
bottleneck: 1.0.0
tables: 3.2.0
numexpr: 2.4.4
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.5
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: None
The text was updated successfully, but these errors were encountered: