Ejemplo n.º 1
0
def test_grouped_mutate_repeated_keys():
    df = mtcars.copy()
    df.index = list(range(16)) + list(range(16))
    with pytest.raises(ValueError):  # cannot reindex from duplicate axis
        with dppd(df) as (ddf, X):
            ddf.groupby("cyl").mutate(grp_rank={
                grp: sub_df.hp.rank()
                for (grp, sub_df) in X.itergroups()
            })
Ejemplo n.º 2
0
def test_removes_infinite_values():
    df = mtcars.copy()
    df.loc[[0, 5], 'wt'] = [np.inf, -np.inf]
    p = ggplot(df, aes(x='wt')) + geom_bar()

    with pytest.warns(UserWarning) as record:
        p._build()

    def removed_2_row_with_infinites(record):
        for item in record:
            msg = str(item.message).lower()
            if '2 rows' in msg and 'non-finite' in msg:
                return True
        return False

    assert removed_2_row_with_infinites(record)
Ejemplo n.º 3
0
def test_removes_infinite_values():
    df = mtcars.copy()
    df.loc[[0, 5], 'wt'] = [np.inf, -np.inf]
    p = ggplot(df, aes(x='wt')) + geom_bar()

    with pytest.warns(UserWarning) as record:
        p._build()

    def removed_2_row_with_infinites(record):
        for item in record:
            msg = str(item.message).lower()
            if '2 rows' in msg and 'non-finite' in msg:
                return True
        return False

    assert removed_2_row_with_infinites(record)
Ejemplo n.º 4
0
(ggplot(mtcars, aes('wt', 'mpg', color='factor(gear)')) + geom_point() + stat_smooth(method='lm') + facet_wrap('~gear'))

from plotnine import *
(ggplot(mtcars, aes('factor(cyl)', fill='factor(am)')) + geom_bar( position='fill') )

(ggplot(mtcars, aes('factor(cyl)', fill='factor(am)')) + geom_bar(position='fill') + geom_text(aes(label='stat(count)'), stat='count', position='fill' ))

(ggplot(mpg)+ aes(x='manufacturer') + geom_bar(size=20) + coord_flip() + labs(y='Count', x='Manufacturer', title='Number of Cars by Make'))
#https://plotnine.readthedocs.io/en/stable/tutorials/miscellaneous-order-plot-series.html


from pydataset import data
data()
mtcars = data('mtcars')
data1 = mtcars.copy()
data1.head()

mpg = data('mpg')
data2 = mpg.copy()
data2.head()

#barplot
(mpg['manufacturer'].value_counts(sort=False).plot.barh().set_title('Number of Cars by Make'))

#histogram
(mpg['cty'].plot.hist(bins=12))
plt.hist('cty', bins=12, data=mpg)

ggplot(mpg) +  aes(x='cty') +  geom_histogram(binwidth=2)  #plotnine