adding CountryCountsByBatchcodeTablesMerger

This commit is contained in:
frankknoll
2023-06-02 01:06:22 +02:00
parent 1129132dbe
commit 09905eed4d
2 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import pandas as pd
class CountryCountsByBatchcodeTablesMerger:
@staticmethod
def merge(countryCountsByBatchcodeTables):
return (pd
.concat(countryCountsByBatchcodeTables)
.groupby(countryCountsByBatchcodeTables[0].index.names)
.sum())

View File

@@ -0,0 +1,52 @@
import unittest
from pandas.testing import assert_frame_equal
from TestHelper import TestHelper
import pandas as pd
from CountryCountsByBatchcodeTablesMerger import CountryCountsByBatchcodeTablesMerger
class CountryCountsByBatchcodeTablesMergerTest(unittest.TestCase):
def test_merge(self):
# Given
countryCountsByBatchcodeTable1 = TestHelper.createDataFrame(
columns = ['COUNTRY_COUNT_BY_VAX_LOT'],
data = [ [10],
[15]],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT', 'COUNTRY'],
tuples = [['12345', 'Germany'],
['AAA', 'United States']]))
countryCountsByBatchcodeTable2 = TestHelper.createDataFrame(
columns = ['COUNTRY_COUNT_BY_VAX_LOT'],
data = [ [20]],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT', 'COUNTRY'],
tuples = [['12345', 'Germany']]))
# When
dataFrame = CountryCountsByBatchcodeTablesMerger.merge([countryCountsByBatchcodeTable1, countryCountsByBatchcodeTable2])
# Then
assert_frame_equal(
dataFrame,
TestHelper.createDataFrame(
columns = ['COUNTRY_COUNT_BY_VAX_LOT'],
data = [ [10 + 20],
[15]],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT', 'COUNTRY'],
tuples = [['12345', 'Germany'],
['AAA', 'United States']])))
def _getCountryCountsByClickedBatchcode():
exploration = pd.read_csv('src/data/Country By Clicked Batchcode 20230302-20230430.csv', index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7])
exploration.index.name = 'VAX_LOT'
exploration.rename(
columns =
{
'Country': 'COUNTRY',
'Event count': 'COUNTRY_COUNT_BY_VAX_LOT'
},
inplace = True)
exploration.set_index('COUNTRY',append = True, inplace = True)
return exploration