Python Forum
what library for sparklines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what library for sparklines
#1
Bonjour,

import data

# Loading a Sample Pandas DataFrame
import pandas as pd
import numpy as np
import seaborn as sns
 df = sns.load_dataset('titanic')
code is:

def percentile_90(x):
    return x.quantile(.9)

from scipy.stats import trim_mean
def trim_mean_10(x):
    return trim_mean(x, 0.1)

def largest(x):
    return x.nlargest(1)

import matplotlib.pyplot as plt
import base64
from r-ltxsparklines import sparklines 

def sparkline_str(x):
    bins=np.histogram(x)[0]
    sl = ''.join(sparklines(bins))
    return sl

#Les voici tous rassemblés :
agg_func_largest = {
    'fare': [percentile_90, trim_mean_10, largest, sparkline_str]
}
df.groupby(['class', 'embark_town']).agg(agg_func_largest)
that produces:

Input In [82]
from r-ltxsparklines import sparklines
^
SyntaxError: invalid syntax

After other modifications, error is:

NameError: name 'sparklines' is not defined

The question is: how to define 'sparklines' or which libraries to import so that the 'sparklines' function is recognized?

Regards,
Leloup
Larz60+ write Apr-19-2022, 07:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#2
https://pypi.org/project/sparklines/
Reply
#3
If you want to see all packages (some or all may or may not fit your needs): https://pypi.org/search/?q=sparklines
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020