import panda as pd
import numpyas np
import matplotlib.pyplot as plt
## 讀取雲端硬碟中的excel檔
dfIncome=pd.read_excel("/content/drive/My Drive/__DataSet/001_Income_F.xlsx")
dfIncome
---
##總收入與人數
sum=dfIncome['Income'].sum()
n=dfIncome['Income'].count()
print(f'總和={sum}, 樣本數={n}')
##直方圖
plt.hist(dfIncome['Income'], bins=range(0, 100000, 1000))
plt.show()
----
dfLorenz=dfIncome[:]
se=dfLorenz['Income'].sort_values()
cumulativeSum=0
i=0
宣告xx為串列變數
xx=[]
宣告yy為串列變數
yy=[]
手動追蹤看看
for x in se:
i=i+1
cumulativeSum+=x
xx.append(i/n)
yy.append(cumulativeSum/sum)
plt.plot([0,1], linestyle = 'dotted')
#散佈圖
plt.scatter(x=xx,y=yy,s=0.1)
plt.axis('square')
plt.xlim(0,1)
plt.ylim(0,1)
print('羅倫茲曲線(Lorenz curve)')
plt.show()
---
R=np.trapz(x=xx,y=yy) #計算曲線下面積
A=0.5-R
G=A/(A+R)
print(G)

{"metaMigratedAt":"2023-06-17T00:05:58.948Z","metaMigratedFrom":"Content","title":"Untitled","breaks":true,"contributors":"[{\"id\":\"97a62aaa-63e8-4333-b34d-b8caf1ae68d7\",\"add\":861,\"del\":20}]"}