要求:列company_id为非False的行中,汇总列quantity
正确值:500-150-100=250
df[df['company_id']!=False]['quantity'].sum()
附上接口获得的数据–列表嵌套字典转为DataFrame的语句
import pandas as pd
r = [{'quantity': -500.0, 'company_id': False, 'id': 17}, {'quantity': 500.0, 'company_id': [1, 'YourCompany'], 'id': 18}, {'quantity': -150.0, 'company_id': [1, 'YourCompany'], 'id': 21}, {'quantity': 250.0, 'company_id': False, 'id': 22}, {'quantity': -100.0, 'company_id': [2, 'My Company, Chicago'], 'id': 25}]
df = pd.DataFrame(r)