看板 [ Python ]
討論串[問題] txt內容切割加總
共 8 篇文章
首頁
上一頁
1
2
下一頁
尾頁

推噓1(1推 0噓 3→)留言4則,0人參與, 最新作者paladin499 (芭樂丁)時間10年前發表 (2014/11/16 03:58), 10年前編輯資訊
0
0
1
內容預覽:
可以試試dictionary. 假設原txt檔叫number.txt. file=open('number.txt'). Dict={}. for i in range(10):. Dict[i]=0. for num in file:. Dict[int(float(num)%10)]+=floa
(還有78個字)

推噓2(2推 0噓 1→)留言3則,0人參與, 最新作者ypcat ((ノ‵□′)ノ┴┴)時間10年前 (2014/10/28 14:04), 編輯資訊
0
0
1
內容預覽:
# a functional solution. import itertools. for key, group in itertools.groupby(map(float, open('in.txt')), int):. print key, sum(group). --. 發信站: 批踢

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者apua (Apua)時間10年前 (2014/10/22 01:53), 編輯資訊
0
0
1
內容預覽:
.. code:: Python. R = {}. with open(filename) as f:. for line in f:. val = float(line). key = int(line). R[key] = R.get(key, 0) + val. for k in sorted
(還有4個字)

推噓0(0推 0噓 5→)留言5則,0人參與, 最新作者alibuda174 (阿哩不達)時間10年前 (2014/10/11 10:36), 編輯資訊
0
0
1
內容預覽:
假設檔案內容大致如下,已按照整數部分排序,中間可缺某整數區段,. 0.01. 0.02. 0.03. 0.09. 1.03. 1.02. 1.01. 1.04. 1.09. 3.01. 3.22. 3.05. 4.01. 4.03. 4.02. 5.06. 5.01. 5.07. 7.01. 7.0
(還有447個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者painkiller (肚子餓~)時間10年前發表 (2014/10/11 09:35), 10年前編輯資訊
0
0
0
內容預覽:
假設你的檔案裡只有單純一列數字,沒其他文字. 用pandas + numpy 可以簡單處理無事先排序的資料. import pandas as pd. import numpy as np. #讀資料. tab=pd.read_csv('filename.txt',names=['n'],heade
(還有107個字)
首頁
上一頁
1
2
下一頁
尾頁