-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_data_frame.py
More file actions
45 lines (35 loc) · 1.01 KB
/
Copy pathshow_data_frame.py
File metadata and controls
45 lines (35 loc) · 1.01 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""This is the python module used to get data frame from given given map file.
This module takes below parameters.
file -- File that contains map data (Example: data.yaml)
"""
import pandas as pd
import yaml
import argparse
parser = argparse.ArgumentParser(
description='Show dataframe from yaml file (map data)'
)
parser.add_argument(
'-f',
'--file',
required=True,
help='Provide yaml file with data(map) e.g. map_data.yaml')
args = parser.parse_args()
yaml_file = args.file
def get_map_data(file):
"""Gets the yaml file data as string
Parameters:
file (str) : data file with path (ex: data.yaml)
Returns:
str : data content
"""
data = None
with open(file, "r") as stream:
try:
data =yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
return data
map_data = get_map_data(yaml_file)
data_frame = pd.DataFrame(data=map_data)
#print(data_frame.to_string(index=False))
print(pd.json_normalize(map_data))