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.1.0.tar.gz (16.9 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.1.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: heartbeatpy-0.1.0.tar.gz
  • Upload date:
  • Size: 16.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 a78acdc1111bb0f340bae8818c8ac110ff877dfdc748170628058166b7bf7ef3
MD5 812d43b4d58bc973706f1a6ae2436d81
BLAKE2b-256 f9598db16f7715d23315d11669fb5c2fed5609233314d413b85ff9051a5dc9ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: heartbeatpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d92a848b864cc39d0957a0019125f1d8e1aceece5671011fb79113d4d0cf6ea
MD5 d89b8ef0519f833670a3a6b73c70635e
BLAKE2b-256 21f3fcaa38e523966956944ebe478507c6039f8a2b029b161a1c9ad6fed23245

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