Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- one,two,three
- 1,2,3
- 2,3,4
- 3,4,5
- ,two,three
- ,2,3
- ,3,4
- ,4,5
- import csv
- with open('code.csv', 'rb') as input, open('result.csv', 'wb') as output:
- reader = csv.DictReader(input)
- rows = [row for row in reader]
- writer = csv.writer(output, delimiter = ',')
- writer.writerow(["new_one", "new_two", "new_three"])
- for row in rows:
- if 'two' in row:
- writer.writerow(['',row["two"]])
- for row in rows:
- if 'one' in row:
- writer.writerow([row["one"]])
- new_one,new_two,new_three
- ,2
- ,3
- ,4
- 1
- 2
- 3
- for row in rows:
- if 'one' in row:
- writer.writerow([row["one"]])
- new_one,new_two,new_three
- 1,2
- 2,3
- 3,4
- for row in rows:
- if 'one' in row and 'two' in row:
- writer.writerow([row["one"],row["two"]])
- for row in rows:
- writer.writerow([row.get("one", ""), row.get("two", "")])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement