0
こんにちは私は列1から文字列を取得する必要がありますが、セルcointains ' - 'プログラムは次の列(同じ行)から値を取得し、私はそれをしました。うまく動作しますが、それは速く、短いコードで作ることですか?私は好奇心旺盛だが、したくはより速く動作するように何かを学ぶ:)csvを読み込む際にネストされたifsは、それを速くする方法でしょうか?
import csv
file = 'others.csv'
reader = csv.reader(open(file, 'r', newline=''), delimiter=';')
for row in reader:
if row[0] != '-': #1
print(row[0])
elif row[0] == '-':
if row[1] != '-':
print(row[1]) #2 nesting here
elif row[1] == '-':
print(row[3]) #3 nesting here
...
...
...
そしてなめらかの
col1 col2 col3 col4
0 smth1 smth smth smth
1 smth2 - smth smth
2 - smth3 smth smth
3 smth4 smth smth smth
4 - - - smth5
テーブル:)
を.CSVサンプリングし、出力が
smth1
smth2
smth3
smth4
smth5
です
を持つすべての行とはlolumnsありません - 、一度なめらかに発生しなければならないが – MTG
私はeasly xDを説明できますか? – MTG
@MTGそれでは、2番目の部分がなければ問題ありません。 –