Вычитание и присваивание фреймов данных возвращает NA

, когда объект производного класса присваивается объекту базового класса, дополнительные атрибуты объекта производного класса вырезаются (отбрасываются) из объекта базового класса.

class Base { 
int x;
 };

class Derived : public Base { 
 int z; 
 };

 int main() 
{
Derived d;
Base b = d; // Object Slicing,  z of d is sliced off
}
2
задан Poete Maudit 24 March 2019 в 15:17
поделиться

1 ответ

Мне нужно было просто сделать следующее:

df_nireland = df_data[df_data['Geography']=='Northern Ireland'].reset_index(drop=True)
df_wales = df_data[df_data['Geography']=='Wales'].reset_index(drop=True)
df_scotland = df_data[df_data['Geography']=='Scotland'].reset_index(drop=True)
df_engl_n_wales = df_data[df_data['Geography']=='England and Wales'].reset_index(drop=True)

df_england = df_engl_n_wales

df_england['Population'] = df_engl_n_wales['Population'] - df_wales['Population']

или лучше в принципе, так как вы сохраняете индексы исходного кадра данных, это следующее:

df_nireland = df_data[df_data['Geography']=='Northern Ireland']
df_wales = df_data[df_data['Geography']=='Wales']
df_scotland = df_data[df_data['Geography']=='Scotland']
df_engl_n_wales = df_data[df_data['Geography']=='England and Wales']

df_england = df_engl_n_wales

df_england['Population'] = df_engl_n_wales['Population'] - df_wales['Population'].values
0
ответ дан Poete Maudit 24 March 2019 в 15:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: