memoryfm.ScrobbleLog#

class memoryfm.ScrobbleLog(df, *, meta=None, update_meta=True, username=None, tz='Etc/UTC', source='manual')#

Class representing a scrobble log, i.e. a sequence of scrobbles.

Parameters:
dfpd.DataFrame
A pandas DataFrame containing the scrobbles. It must have the following columns:
1. timestamp : str, int, datetime, pd.Timestamp
This column contains timestamps of scrobbles. If int, then it will be assumed to be unix epoch (milliseconds).
2. track : str
This column contains track names.
3. artist : str
This column contains artist names.
There are two optional columns:
1. album : str
This column contains album names.
2. duration : str, int, timedelta, ``pd.timedelta
This column contains durations of scrobbles/listens.
metadict, default None
A dictionary containing metadata with the following schema:
“username” (str, None) : Username for the ScrobbleLog.
“tz” (str) : Timezone IANA string
“num_scrobbles” (last.fm) or “num_listens” (str) : Number of scrobbles/listens.
“date_range” (dict) : A dictionary with keys,
1. “start” (str, None) : Date of first scrobble in isoformat
2. “end” (str, None) : Date of last scrobble in isoformat.
“source” (str, None) : Source of data (lastfmstats/spotify).
“duration_present” (bool) : True if duration column present.
“memoryfm.version” (str) : Version of memory.fm.
“schema_version” (int) : Version of metadata schema.
update_metabool, default True

If True, then meta is updated.

usernamestr, default None

username used while generating meta if no meta is passed.

tzstr, default “Etc/UTC”

tz value used while generating meta if no meta is passed.

sourcestr, default “manual”

source used while generating meta if no meta is passed.

See also

meta_generator

Generates meta from username, tz, and source

__init__(df, *, meta=None, update_meta=True, username=None, tz='Etc/UTC', source='manual')#

Methods

__init__(df, *[, meta, update_meta, ...])

append(scrobbles[, drop_duplicates])

Append scrobble(s) to a ScrobbleLog.

copy()

filter_by_date([start, end, unit, include_end])

Create a ScrobbleLog filtered by date.

from_dict(data[, orient])

Create a ScrobbleLog from a canonical dict representation.

from_json([file])

Create ScrobbleLog from a canonical JSON.

from_parquet(meta_file, df_file[, start, ...])

Create a ScrobbleLog from a canonical parquet export.

from_scrobble(scrobble, meta, username, tz)

Create a ScrobbleLog from a Scrobble.

head([n])

Create a ScrobbleLog containing the first n scrobbles from the original.

tail([n])

Create a ScrobbleLog containing the last n scrobbles from the original.

to_csv([file, orient])

Write ScrobbleLog to CSV format.

to_dict([orient])

Canonical dict representation of the ScrobbleLog

to_json([file, orient, datetimefmt])

Convert a ScrobbleLog to a canonical JSON.

to_markdown([file, maxcolwidths, tablefmt, ...])

Print ScrobbleLog in a nice looking markdown format.

to_parquet(meta_file, df_file)

Write ScrobbleLog to canonical parquet.

top_charts([kind])

Get top n tracks/artists/albums by number of scrobbles.

tz_convert(tz[, inplace])

Convert ScrobbleLog timezone to another timezone.

Attributes

df

DataFrame containing scrobbles, normalised with required columns and dtypes.

meta

A dictionary containing the following metadata:

tz

The timezone for the ScrobbleLog.

username

The username for the ScrobbleLog