Skip to main content

Heartbeat survey analysis in python

Project description

heartbeatpy

Heartbeat survey analysis in python, inspired by the R packages "heaRtbeat" and "heartbeat". For more information on heartbeat analysis, check out the 2021 Wiley Award for Excellence in Survey Research

Example usage

heartbeatpy has one main function: calculate_votes() which takes in a dataframe of survey data, a list of the columns to perform heartbeat transformation on, and a standard deviation threshold.

import pandas as pd
import numpy as np
from heartbeatpy import create_sample_data, calculate_votes

df, _ = create_sample_data(ncols=2, nrows=10)
votes, stats = calculate_votes(data=df, columns=["Q1", "Q2"], threshold=.5)

The function calculate_votes() returns two objects, the first, votes, contains the data provided to the function with each specified column's likert data replaced with upvotes and downvotes:

votes.head()

	ID	Q1	Q2
0	1	1	-1
1	2	1	-1
2	3	-1	1
3	4	-1	1
4	5	1	-1

The second object returned by calcuate_votes() is stats, which contains the standard deviation for each indiviual (row) in the data.

stats.head()

individual_sd	individual_mean
0	1.414214	3.0
1	2.121320	2.5
2	1.414214	2.0
3	0.707107	1.5
4	0.707107	1.5

After finding votes, the function calculate_summary() can be used to generate the percent of downvotes, neutral votes, and upvotes for each question. calculate_summary() also calculates controversy score for each question.

from heartbeatpy import calculate_summary

summary = calculate_summary(votes=votes, columns=cols)

summary.head()
	Question	Upvote	Downvote	Neutral	Controversy_Score
0	Q1			0.3		0.3			0.4		1.5	
1	Q2			0.4		0.4			0.2		4.0

Lastly, you can use the built-in visualize_heartbeat() function to generate an altair stacked bar chart visualization:

import altair as alt
from heartbeatpy import visualize_heartbeat

chart = visualize_heartbeat(summary)
display(chart)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

heartbeatpy-0.2.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heartbeatpy-0.2.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file heartbeatpy-0.2.0.tar.gz.

File metadata

  • Download URL: heartbeatpy-0.2.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for heartbeatpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4afafcc9c887c13defe833a63bcf09b27affe0fef14f90cc10420042449d624c
MD5 17bbde6dff6a6eff4d56e35f1dc0619c
BLAKE2b-256 bc27ec6a488aed7a6d31144c639335298db84325511eccb40e652cf8535c3129

See more details on using hashes here.

File details

Details for the file heartbeatpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: heartbeatpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for heartbeatpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4539b597ca5a91f5369295058954aad6638f1543db9f4252474bc4376992e651
MD5 b488f97f7ecd620c532c5c68ab8ca3a3
BLAKE2b-256 95ce0fb452426ab993c1884a4c1a4e365947c34652220b222651fbdf4075be93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page