How to group and sum some results in others ( Style format in Euros)

折月煮酒 提交于 2020-02-07 05:28:07

问题


I want to make a pie chart over Europe and some specific countries, i need to groupe and sum some countries or companies in a group call "Others", for example: all the companies that have the budget less than 10000 euros.

import pandas as     pd
from   pandas import Series, DataFrame
import numpy  as     np
import matplotlib.pyplot as plt

    Year    Project Entity  Participation   Country Budget
0   2015    671650 - MMMAGIC - 5G   FUNDACION IMDEA NETWORK*    Participant Spain   € 304,000
1   2015    671650 - MMMAGIC - 5G   ROHDE & SCHWARZ GMBH*   Participant Germany € 120,000
2   2015    671650 - MMMAGIC - 5G   SAMSUNG ELECTRONICS (UK) LIMITED    Coordinator UnitedKingdom   € 797,500
3   2015    671650 - MMMAGIC - 5G   HUAWEI TECHNOLOGIES DUESSELDORF GMBH    Participant Germany € 648,000
4   2015    671650 - MMMAGIC - 5G   TELEFONICA INVESTIGACION Y DESARROLLO SA*   Participant Spain   € 531,976
5   2015    671650 - MMMAGIC - 5G   CHALMERS TEKNISKA HOGSKOLA AB*  Participant Sweden  € 233,000

datos1 = (df[(df['Project'].str.contains('5G-MOBIX')) & (df.Country.str.count('Spain'))])
datos2 = 'La cantidad de proyectos es ='
datos4= 'El presupuesto total en Euros es ='
print(df[(df['Project'].str.contains('5G-MOBIX')) & (df.Country.str.count('Spain'))& (df['Country'].replace(!=''NOKIA SPAIN SA'','Other')]) 
print(datos2, datos1.Country.str.count('Spain').sum())
print(datos4, datos1.Budget.sum())

I have an error with the command "replace".

datos1 = (df[(df['Project'].str.contains('5G-MOBIX')) & (df.Country.str.count('Spain'))])
datos2 = 'La cantidad de proyectos es ='
datos4= 'El presupuesto total en Euros es ='
print(df[(df['Project'].str.contains('5G-MOBIX')) & (df.Country.str.count('Spain'))& (df['Country'].replace(!=''NOKIA SPAIN SA'','Other')]) 
print(datos2, datos1.Country.str.count('Spain').sum())
print(datos4, datos1.Budget.sum())

explode = (0.1, 0, 0, 0)
datos1.groupby("Entity")["Budget"].sum().plot(kind="pie", explode=explode, counterclock=False, autopct='%1.1f%%', shadow=True, startangle=90, figsize=(10, 8))
plt.axis('equal')
plt.title("SPAIN in the project 5G-MOBIX", bbox={"facecolor":"0.5", "pad":5}, color='b')
plt.ylabel('')
plt.show()

i expect this result in the pie chart:

     Year       Project     Entity  Country   Budget                                                                             
742  2018   825496 - 5G-MM  'NOK'   Spain     € 556815.21                                                                       
743  2018   825496 - 5G-MM  'TDE'   Spain     € 747879.88                                                              
778  2018   825496 - 5G-MM  'ALS'   Spain     € 152868.86                                                                        
780  2018   825496 - 5G-MM  'OTHER' Spain     € 300000 

来源:https://stackoverflow.com/questions/57688183/how-to-group-and-sum-some-results-in-others-style-format-in-euros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!