我正在尝试根据一个公共因素将行进行多行分组,并通过聚合函数将各列加在一起。但是,我希望将NaN值视为NaN而不是0。
我尝试使用skipna和nansum,但是我的代码无法运行。
我的数据将是这样的:
cmake_minimum_required(VERSION 3.5)
execute_process(COMMAND python3 -c "import tensorflow; print(tensorflow.sysconfig.get_include())" OUTPUT_VARIABLE Tensorflow_INCLUDE_DIRS)
set (CMAKE_CXX_FLAGS "--std=c++11 -fPIC -O2 -D_GLIBCXX_USE_CXX11_ABI=0")
link_directories("/miniconda/envs/py36/lib/python3.6/site-packages/tensorflow")
include_directories(${Tensorflow_INCLUDE_DIRS})
include_directories("/usr/local/include")
add_library(fst_decoder SHARED fst_decoder.cc simple_decoder.cc)
target_link_libraries(fst_decoder -ltensorflow_framework -lfst -ldl -lm)
name A B C D E
john 1 0 5 NaN 1
john 2 NaN 0 NaN 3
Jon 4 2 1 3 NaN
Jon NaN 0 1 3 4
我希望输出看起来像这样:
aggregate_functions = {'A':'Sum', 'B':'Sum', 'C':'Sum', 'D':'Sum', 'E':'Sum'}
testing = testing.groupby(testing['Name']).aggregate(aggregate_functions)
实际输出是这样:
name A B C D E
john 3 0 5 NaN 4
Jon 4 2 2 6 4