一つの可能な解決策であれば一意単調指数(0,1,2,...
):
for i, row in testDF.iterrows():
print("Currently on row: {}; Currently iterrated {}% of rows".format(i, (i + 1)/len(testDF.index) * 100))
サンプル:
np.random.seed(1332)
testDF = pd.DataFrame(np.random.randint(10, size=(10, 3)))
print (testDF)
0 1 2
0 8 1 9
1 4 3 5
2 0 1 3
3 1 8 6
4 7 4 7
5 7 5 3
6 7 9 9
7 0 1 2
8 1 3 4
9 0 0 3
for i, row in testDF.iterrows():
print("Currently on row: {}; Currently iterrated {}% of rows".format(i, (i + 1)/len(testDF.index) * 100))
Currently on row: 0; Currently iterrated 10.0% of rows
Currently on row: 1; Currently iterrated 20.0% of rows
Currently on row: 2; Currently iterrated 30.0% of rows
Currently on row: 3; Currently iterrated 40.0% of rows
Currently on row: 4; Currently iterrated 50.0% of rows
Currently on row: 5; Currently iterrated 60.0% of rows
Currently on row: 6; Currently iterrated 70.0% of rows
Currently on row: 7; Currently iterrated 80.0% of rows
Currently on row: 8; Currently iterrated 90.0% of rows
Currently on row: 9; Currently iterrated 100.0% of rows
EDI T:length of df
のと同じであるどのようないくつかのカスタムインデックスの値であれば
、length of index
によってzip
とnumpy.arange
と解決策:すべてのiterrows
の
np.random.seed(1332)
testDF = pd.DataFrame(np.random.randint(10, size=(10, 3)), index=[2,4,5,6,7,8,2,1,3,5])
print (testDF)
0 1 2
2 8 1 9
4 4 3 5
5 0 1 3
6 1 8 6
7 7 4 7
8 7 5 3
2 7 9 9
1 0 1 2
3 1 3 4
5 0 0 3
for i, (idx, row) in zip(np.arange(len(testDF.index)), testDF.iterrows()):
print("Currently on row: {}; Currently iterrated {}% of rows".format(idx, (i + 1)/len(testDF.index) * 100))
Currently on row: 2; Currently iterrated 10.0% of rows
Currently on row: 4; Currently iterrated 20.0% of rows
Currently on row: 5; Currently iterrated 30.0% of rows
Currently on row: 6; Currently iterrated 40.0% of rows
Currently on row: 7; Currently iterrated 50.0% of rows
Currently on row: 8; Currently iterrated 60.0% of rows
Currently on row: 2; Currently iterrated 70.0% of rows
Currently on row: 1; Currently iterrated 80.0% of rows
Currently on row: 3; Currently iterrated 90.0% of rows
Currently on row: 5; Currently iterrated 100.0% of rows
なぜループを使用して始めていますか?おそらくもっと良い方法があります。必要な場合は、行の総数で割ることができる現在の行のインデックス(行自体とともに)を返す 'enumerate'を使って、進捗状況を簡単に計算できます。 'progress = index/len(testDF)' – DeepSpace
私はジオコーディングされたデータで新しい列を作成しているので、iterrowsループを使用しています。ジオコードできるサービスのほとんどには制限があるため、私のループには0.1秒の遅延が追加されています。 – christaylor