portfolio 테이블, 고객 행동 기록 데이터를 담은 transcript 테이블, 고객 정보를 담은 profile 테이블로 구성

✅ Portfolio 테이블 설명 → 프로모션 정보 테이블
수신 가능한 프로모션 제안에 대한 정보와 각 프로모션의 유형, 프로모션 기간, 보상 그리고 해당 프로모션이 고객에게 어떻게 배포 되었는지에 대한 기본 정보
1-1) reward
1-2) channels
1-3) difficulty
1-4) duration
1-5) offer_type
1-6) id

✅ profile 테이블 설명 → 고객 정보 테이블
- 각 사람에 대한 연령, 급여, 성별과 같은 차원 데이터를 포함
- 각 기록에는 하나의 고유한 고객이 포함되어 있음
2-1) gender
O, Nan은 데이터에서 제거O , Nan 에 해당# gender 컬럼의 Value_count
profile['gender'].value_counts(dropna=False)
'''
gender
M 8484
F 6129
NaN 2175
O 212
'''
2-2) age
# age 컬럼 결측치 조회
null_cnt = profile['age'].isna().sum()
# min, max 값 조회
max_age = max(profile['age'])
min_age = min(profile['age'])
print(f'결측치: {null_cnt}')
print(f'max: {max_age}, min: {min_age}')
2-3) id
transcript 테이블의 person과 연결# id 컬럼 null값 조회
profile['id'].isna().sum()
# 중복값 개수 조회
profile['id'].duplicated().sum()
2-4) became_member_on
# became_member_on 결측치 조회
profile['became_member_on'].isna().sum()
# dtype 조회
profile['became_member_on'].dtypes
# min, max 값 조회
max(profile['became_member_on'])
min(profile['became_member_on'])
2-5) income
# income 결측치 조회
profile['income'].isna().sum()
# min, max 값 조회
max(profile['income'].dropna())
min(profile['income'].dropna())
→ max 연산자 사용 했더니 결과값이 nan으로 나왔다 .. ⇒ 결측값 제거 후 다시 연산해서 해결!

✅ transcript 테이블 설명 ⇒ 프로모션 수신 기록 테이블
- 기록에는 고객이 받은 프로모션 오퍼의 여러 단계가 표시
- 프로모션 수신의 고유 값은 수신, 보기, 완료
- 고객이 고객이 된 이후 시간 동안 수행한 다양한 거래도 확인 가능
- 모든 기록을 통해 스타벅스와 상호작용한 날짜와 금액도 확인 가능
3-1) person
profile 테이블의 id 와 연결3-2) event

# event 컬럼의 Value Count
event_value_cnt = transcript['event'].value_counts(dropna=False)
event_value_cnt = pd.DataFrame(event_value_cnt).reset_index()
event_value_cnt
bar = plt.bar(event_value_cnt['event'], event_value_cnt['count'])
for rect in bar:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2.0, height, '%.1f' % height, ha='center', va='bottom', size = 9)
3-3) value
3-4) time
profile['became_member_on'] = pd.to_datetime(profile['became_member_on'])# df.shape = (행 개수, 열 개수) 튜플 반환
# 80세 이상 데이터 수
profile[profile['age'] >= 80].shape[0]
# 90세 이상 데이터 수
profile[profile['age'] >= 90].shape[0]
json 형태의 데이터를 꺼내 개별 컬럼에 추가해주는 작업 진행
[ 세부 작업 내용 ]
pd.json_normalize() 바로 적용하려 했는데 에러 발생
ast 모듈의 literal_eval 사용하여 Dict 타입으로 변환
json_normalize 활용하여 별도의 테이블로 추출# value 컬럼 데이터 형 변환
transcript['value'] = [literal_eval(x) for x in transcript['value']]
# json_normalize() : 딕셔너리 => 테이블로 변환
value_df = pd.json_normalize(transcript['value'])
value_df

offer_id , offer id)offer_id의 결측 값을 offer id 의 값으로 대체# offer_id 컬럼의 결측값에 offer id 컬럼값 입력
value_df['offer_id'] = value_df['offer_id'].fillna(value_df['offer id'])
# 기존 테이블(transcript)에 value 값 합치기
transcript['value_offer_id'] = value_df['offer_id']
transcript['value_amount'] = value_df['amount']
transcript['value_reward'] = value_df['reward']
