は、第三に、あなたはそれが、この場合にはそうで揃えることができる何かを返す必要がSeries
:私はトンを得る
In [213]:
df = pd.DataFrame(np.full((6), 1))
def func(row):
l = np.full((np.random.random_integers(5)), 1)
return pd.Series(np.hstack((l, row)))
In [214]:
df.apply(func, axis=1)
Out[214]:
0 1 2 3 4 5
0 1.0 1.0 1.0 NaN NaN NaN
1 1.0 1.0 NaN NaN NaN NaN
2 1.0 1.0 NaN NaN NaN NaN
3 1.0 1.0 1.0 NaN NaN NaN
4 1.0 1.0 1.0 1.0 1.0 NaN
5 1.0 1.0 1.0 1.0 1.0 1.0
注意
C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\numpy\core\numeric.py:301: FutureWarning: in the future, full(3, 1) will return an array of dtype('int32')
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\numpy\core\numeric.py:301: FutureWarning: in the future, full(2, 1) will return an array of dtype('int32')
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\numpy\core\numeric.py:301: FutureWarning: in the future, full(1, 1) will return an array of dtype('int32')
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\numpy\core\numeric.py:301: FutureWarning: in the future, full(4, 1) will return an array of dtype('int32')
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\numpy\core\numeric.py:301: FutureWarning: in the future, full(5, 1) will return an array of dtype('int32')
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
DFコール属性values
からNPの配列を取得するには:
上記に関する警告の
df.apply(func, axis=1).values
'random_integet'はnp関数ではありません – EdChum
@EdChumを実行してコードを更新できますか?私はすでに間違いを訂正しています。おかげで – user5779223