-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Description
In [82]: def func_tuple(x):
....: return (x,x)
....:
In [83]: series = pandas.Series(['a', 'b', 'c', 'd'])
In [84]: df = pandas.DataFrame({'A': series})
In [85]: df
Out[85]:
A
0 a
1 b
2 c
3 d
In [86]: df.applymap(func_tuple)
Out[86]:
A
0 None
1 None
2 None
3 None
This works fine
In [87]: map(func_tuple, series)
Out[87]: [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'd')]
Let`s try with a list:
In [88]: def func_list(x):
....: return [x,x]
In [89]: df.applymap(func_list)
Out[89]:
A
0 ['a', 'a']
1 ['b', 'b']
2 ['c', 'c']
3 ['d', 'd']
Had a look at the pandas.DataFrame.applymap() code and this behavior is related to numpy.
I`m using numpy 1.5.1, i know that for other reason numpy 1.6.1 is preferred. Would more recent numpy version fix this?
I tried to install more recent version of numpy, but so far unsuccessful (various compilation errors).
In [103]: np.frompyfunc(func_tuple, 1, 1)(series)
Out[103]:
0 NaN
1 NaN
2 NaN
3 NaN
In [104]: np.frompyfunc(func_list, 1, 1)(series)
Out[104]:
0 ['a', 'a']
1 ['b', 'b']
2 ['c', 'c']
3 ['d', 'd']