DataFrame-level Analysis Examples#

Basic examples of analysis methods.

Used Libraries#

The following methods selectively use these libraries:

import plotly.io as pio
pio.renderers.default = "notebook"

Cohort Analysis#

cohort() - Analyzes customer behavior over time

from frameon import load_dataset, FrameOn as fo

superstore = fo(load_dataset('superstore'))
fig = superstore.analysis.cohort(
    user_id_col='Customer ID', 
    date_col='Order Date', 
    revenue_col='Sales',
    granularity='quarter',
    include_period0=False,
    width=900,
    height=500
)
fig.show()

Correlation Analysis#

corr_matrix() - Shows relationships between numeric variables

from frameon import load_dataset, FrameOn as fo

iris = fo(load_dataset('iris')).drop('species_id', axis=1)
fig = iris.analysis.corr_matrix()
fig.show()

RFM Analysis#

rfm() - Segments customers based on recency, frequency and monetary value

from frameon import load_dataset, FrameOn as fo

superstore = fo(load_dataset('superstore'))
rfm_res = superstore.analysis.rfm(
    user_id_col='Customer ID', 
    date_col='Order Date', 
    revenue_col='Sales'
)
rfm_res['hist'].show()
rfm_res['heat_pairs'].show()
rfm_res['seg_tree'].show()

Segment Analysis#

segment_polar() - Shows metric profiles across segments

from frameon import load_dataset, FrameOn as fo

diamonds = fo(load_dataset('diamonds'))
labels = {
    'price': 'Price',
    'carat': 'Carat',
    'depth': 'Depth',
    'table': 'Table',
    'cut': 'Cut',
}
fig = diamonds.analysis.segment_polar(
    metrics=['price', 'carat', 'depth', 'table'],
    dimension='cut',
    count_column='price',
    labels=labels
)
fig.show()

Metric by Dimensions#

metric_by_dimensions_plot() - Analyzes metrics across multiple dimensions

from frameon import load_dataset, FrameOn as fo

tips = fo(load_dataset('tips'))
labels = {
    'total_bill': 'Total Bill',
    'sex': 'Sex',
    'smoker': 'Smoker',
    'day': 'Day',
    'time': 'Time',
}
fig = tips.analysis.metric_by_dimensions_plot(
    metric='total_bill',
    dimensions=['sex', 'smoker', 'day', 'time'],
    agg_func='mean',
    facet_col_wrap=2,
    facet_row_spacing=0.15,
    facet_col_spacing=0.07,
    labels=labels,
    text_auto='.1f',
    width=800
)
fig.show()

Text Sentiment Analysis#

sentiment() - Analyzes sentiment in text data

from frameon import load_dataset, FrameOn as fo

reviews = fo(load_dataset('reviews'))
fig = reviews.analysis.sentiment(text_column='Text')
fig.show()

Word Frequency Analysis#

word_frequency() - Shows most frequent words in text

from frameon import load_dataset, FrameOn as fo

reviews = fo(load_dataset('reviews'))
fig = reviews.analysis.word_frequency(
    text_column='Text', 
    n=10,
    text_auto=True
)
fig.show()