pandas ile Pazarlama Kampanyalarını Analiz Etme
Jill Rosok
Data Scientist
# Tek bir sütunun veri türünü yazdırın
print(marketing['converted'].dtype)
dtype('object')
# Bir sütunun veri türünü değiştirin marketing['converted'] = marketing['converted']\ .astype('bool')print(marketing['converted'].dtype)
dtype('bool')
marketing['is_house_ads'] = np.where(
marketing['marketing_channel'] == 'House Ads',
True, False
)
print(marketing.is_house_ads.head(3))
0 True
1 False
2 True
Name: is_house_ads, dtype: bool
channel_dict = {"House Ads": 1, "Instagram": 2, "Facebook": 3, "Email": 4, "Push": 5}marketing['channel_code'] = marketing['marketing_channel']\ .map(channel_dict) print(marketing['channel_code'].head(3))
0 1
1 1
2 1
Name: channel_code, dtype: int64
# Tarih sütunlarını parse_dates ile okuyun
marketing = pd.read_csv('marketing.csv',
parse_dates=['date_served',
'date_subscribed',
'date_canceled'])
# Veya
# Mevcut sütunu datetime türüne dönüştürün
marketing['date_served'] = pd.to_datetime(
marketing['date_served']
)
# Veya her sütunu tek tek dönüştürün
# Mevcut sütunu datetime türüne dönüştürün
marketing['date_served'] = pd.to_datetime(
marketing['date_served']
)
marketing['day_served'] = marketing['date_served']\
.dt.dayofweek
pandas ile Pazarlama Kampanyalarını Analiz Etme