-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile2.py
26 lines (20 loc) · 811 Bytes
/
file2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import csv
# open required csv and read it as a text string
with open('file1.csv', 'r') as input:
csv_reader = csv.DictReader(input)
# open new file to save changes
with open('file2.csv', 'wb') as out_file:
fieldnames = ['ParkName', 'State', 'partySize', 'RateType', 'BookingType', 'Equipment']
output_data = csv.DictWriter(out_file, fieldnames=fieldnames, delimiter =',')
output_data.writeheader()
#removing not required columns
for line in csv_reader:
del line['Country']
del line['Adult']
del line['Child']
del line['BookingStartDate']
del line['BookingEnddate']
del line['Night']
del line['Permits']
output_data.writerow(line)
print("Writing complete")