導航:首頁 > 編程語言 > pythonexcel數據計算

pythonexcel數據計算

發布時間:2024-09-17 00:45:47

㈠ 求數據總共多少行多少列python(excel怎麼統計一共多少行數)

導讀:本篇文章首席CTO筆記來給大家介紹有關求數據總共多少行多少列python的相關內容,希望對大家有所幫助,一起來看看吧。

pythonnumpy求矩陣有多少列

想知道矩陣A的行數和列數用np.size()函數

np.size(A,0)為矩陣A的行數

np.size(A,1)為矩陣A的列數

(x,y)=np.shape(A)分別求矩陣的行和列

pandas如何統計excel中列數據的行數?

准備測試數據:

測試數據

打開PyCharm輸入以下代碼

程序代碼

運行效果如下:

運行效果展示

附上實現代碼:

#!/usr/bin/envpython

importpandasaspd

OPENPATH='test.xls'

SAVEPATH='test1.xls'

deftotal_count(path=OPENPATH,sheetname='testsheet'):

df=pd.read_excel(path,sheet_name=sheetname,names=['值','計數'])

#獲取統計項目

item_name=set(df['值'])

#創建字典統計

total_dict=dict(zip([iforiinitem_name],[

0for_inrange(len(item_name))]))

#遍歷」值「列,逐個統計數量

forindex,iteminenumerate(df['值']):

#如果在set中

ifiteminitem_name:

#加入計數統計

total_dict[item]+=df['計數'][index]

#返回

returntotal_dict

defdatato_excel(path=SAVEPATH,sheet_name='total',data_dict={}):

report_df=pd.DataFrame.from_dict(data_dict,orient='index')

xl_writer=pd.ExcelWriter(path)

report_df.to_excel(xl_writer,sheet_name)

try:

xl_writer.save()

print('Savecompleted')

except:

print('Errorinsavingfile')

if__name__=="__main__":

datato_excel(data_dict=total_count())

不知道這是不是您想要的結果,如果有幫助,請採納一下,謝謝!

python判斷數據框有幾行幾列

如果你的第一列是groupby好的,那用一個last_row_index和current_row_index可以O(n)搞定合並,譬如說

intlast=0;

intcurrent=1;

while(currentnumbers.GetLengths(0))

{

if(numbers[last][0]==numbers[current][0])

{

for(inti=1;inumbers.GetLengths(1);i++)

{

numbers[last][i]+=numbers[current][i];

}

}

else

{

last++;

for(inti=0;inumbers.GetLengths(1);i++)

{

numbers[last][i]=numbers[current][i];

}

}

current++;

}

結語:以上就是首席CTO筆記為大家整理的關於求數據總共多少行多少列python的相關內容解答匯總了,希望對您有所幫助!如果解決了您的問題歡迎分享給更多關注此問題的朋友喔~

閱讀全文

與pythonexcel數據計算相關的資料

熱點內容
單片機延時程序計算 瀏覽:442
編譯原理語法翻譯 瀏覽:502
pr編譯出錯渲染存在偏移 瀏覽:260
如何製作自家的app 瀏覽:197
推薦一個解壓軟體rar解壓幫手 瀏覽:207
wd文檔加密器 瀏覽:745
伺服器上傳壓縮包一般是什麼格式 瀏覽:331
發送加密文件密碼幾位數 瀏覽:158
樹洞app怎麼樣 瀏覽:173
vivo編譯時間可以改么 瀏覽:149
編譯和編輯怎麼區分 瀏覽:979
iar編譯文件順序 瀏覽:898
java二叉搜索樹 瀏覽:633
王者怎麼看好友的伺服器 瀏覽:733
無線編碼單片機 瀏覽:464
天聯高級版域名伺服器地址 瀏覽:206
鴻蒙用什麼編譯 瀏覽:730
伺服器如何迅速擴容 瀏覽:792
伺服器無固定ip地址不 瀏覽:643
安卓手機如何折扣充值 瀏覽:996