Skip to content

Commit

Permalink
refactor: Add column to data frame inplace
Browse files Browse the repository at this point in the history
  • Loading branch information
rouille committed Feb 5, 2020
1 parent 763074f commit cc39be2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 1 addition & 4 deletions powersimdata/input/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ def csv_to_data_frame(data_loc, filename):


def add_column_to_data_frame(data_frame, column_dict):
"""Adds column(s) to data frame
"""Adds column(s) to data frame. Done inplace.
:param pandas.DataFrame data_frame: input data frame
:param dict column_dict: column to be added. Keys are column name and
values a list of of values.
:return: (*pandas.DataFrame*) -- data frame with extra column(s)
"""
for key, value in column_dict.items():
data_frame[key] = value

return data_frame
6 changes: 3 additions & 3 deletions powersimdata/input/usa_tamu_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ def get_zone_name(idx):
extra_col_bus = {
'lat': get_lat(model.bus.index),
'lon': get_lon(model.bus.index)}
model.bus = add_column_to_data_frame(model.bus, extra_col_bus)
add_column_to_data_frame(model.bus, extra_col_bus)

extra_col_plant = {
'lat': get_lat(model.plant.bus_id),
'lon': get_lon(model.plant.bus_id),
'zone_id': get_zone_id(model.plant.bus_id),
'zone_name': get_zone_name(model.plant.bus_id)}
model.plant = add_column_to_data_frame(model.plant, extra_col_plant)
add_column_to_data_frame(model.plant, extra_col_plant)

extra_col_branch = {
'from_zone_id': get_zone_id(model.branch.from_bus_id),
Expand All @@ -201,5 +201,5 @@ def get_zone_name(idx):
'from_lon': get_lon(model.branch.from_bus_id),
'to_lat': get_lat(model.branch.to_bus_id),
'to_lon': get_lon(model.branch.to_bus_id)}
model.branch = add_column_to_data_frame(model.branch, extra_col_branch)
add_column_to_data_frame(model.branch, extra_col_branch)
return model

0 comments on commit cc39be2

Please sign in to comment.