13 Nisan 2022 Çarşamba

A/B Test Data Munging: Changing a two-column number data to one-column number and group labels

Before doing an A/B test, data may come in different formats such as two data frames or a dataframe with two columns consisting of Group A figures and Group B figures respectively.

In such cases we may need to reorganize the data so that one column consists of the figures and the second column shows their respective groups. Here is a concise method of doing this:




#Data A and Group A
Group_A = np.arange(len(A))
Group_A = pd.DataFrame(Group_A)
Group_A[:] = "A"
A = pd.concat([A, Group_A], axis = 1)

#Data B and Group B
Group_B = np.arange(len(B))
Group_B = pd.DataFrame(Group_B)
Group_B[:] = "B"
B = pd.concat([B, Group_B], axis = 1)

#All data in one DF
AB = pd.concat([A,B])
AB.columns = ["Income","Group"]
print(AB.head())
print(AB.tail())

Hiç yorum yok:

Yorum Gönder