Skip to content

Commit c991c90

Browse files
committed
convert the pixel aggregation results to percent
1 parent 85697df commit c991c90

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import csv
2+
import pandas as pd
3+
import os
4+
import argparse
5+
6+
def parse_args():
7+
parser = argparse.ArgumentParser(description='Convert all columsn to percent')
8+
parser.add_argument('--input-path',required=True, help='Input CSV path')
9+
parser.add_argument('--output-path',required=True, help='Output CSV path')
10+
args = parser.parse_args()
11+
return args
12+
13+
14+
15+
def convert_to_percent(csv_file, output_csv):
16+
new_output = {}
17+
pixel_df = pd.read_csv(csv_file)
18+
pixel_df.rename(columns = {'Unnamed: 0':'CensusTract'}, inplace = True)
19+
pixel_df.iloc[:,1:-1] = pixel_df.iloc[:,1:-1].div(pixel_df.total, axis=0)
20+
pixel_df.to_csv(output_csv)
21+
22+
23+
24+
if __name__ == '__main__':
25+
args = parse_args()
26+
file_path = args.input_path
27+
output = args.output_path
28+
convert_to_percent(file_path, output)
29+
30+
31+

0 commit comments

Comments
 (0)