Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Basic Power Analysis Discrepancy

Hi all,

I'm working on a power analysis to better understand how the process works for linear regression and interactions effects. I'm trying to create a function that simulates a dataset, adds participants to it based on an argument that can be specified (e.g., to see how many more people one would need to have power reach a certain threshold), and then counts a proportion of p-values less than an alpha level. In this case, the model is
dv ~ dx_status + ybocs + dx_status*ybocs
and I'm interested in learning how many participants I'd need to get a statistically significant p-value for the interaction term.

Here is the code:

import pandas as pd
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf

hyp2_pvalues_list = [] #create an empty list
np.random.seed(4) #sets a seed for the random number generator
def pwrcurve_hypoth2(addtogroup = 0, simulations = 1000, es = 0.5, dv_sd = 3.9, bdi_sd = 5, ybocs_sd = 5,
alpha = .05):
for x in range(simulations):


/r/pystats
https://redd.it/lumrgk
Release: NiceGUI 1.2.7 with ui.download, easier color definitions, "aggrid from pandas dataframe" and much more

With 21 contributors the just released NiceGUI 1.2.7 is again a wonderful demonstration of the strong growing community behind our easy to use web-based GUI library for Python. NiceGUI has a very gentle learning curve while still offering the option for advanced customizations. By following a backend-first philosophy you can focus on writing Python code. All the web development details are handled behind the scenes.


### New features and enhancements
- introduce `ui.download`
- introduce color arguments for elements like ui.button that accept Quasar, Tailwind, and CSS colors
- allow running in Python’s interactive mode by auto-disabling reload
- allow creating ui.aggrid from pandas dataframe
- fix navigation links behind reverse proxy with subpath
- allow sending "leading" and/or "trailing" events when throttling
- raise an exception when hiding internal routes with app.add_static_files
- add “dark” color to ui.colors

### Documentation
- enhance Trello "drag and drop" example to use a ToDo data model
- add workaround to docs for native mode when WebView2Loader.dll fails load
- add documentation and demo about element borders inside a ui.card
- add hint about exception when running executable with no console on Windows

Of course the release also includes some bugfixes (see release notes for details). Thanks to everyone who was involved in making this release happen.

/r/Python
https://redd.it/12m03v5
Automating the creation of Forms, Views, and Templates

I'm trying to use a couple loops to automatically build from the models each form, view, and url, and have a single template file render each list. I'm newer to python but I do know generating classes and functions like this is not best practice to say the least, however its something I wanted to try for my own project. What I'm interested in is playing with on the front end with my primary fact table and not the two dozen or so dimension tables, which may require frequent field additions or abstractions.

base/app/models.py

from django.db import models
from django.contrib.auth.models import User

#Create your models here.

class UserTypeModel(models.Model):
code = models.CharField(max
length = 10, primarykey = True)
name = models.CharField(max
length = 100, blank = False, unique = True)

def str(self):
return self.name



/r/djangolearning
https://redd.it/135v43t
Cant register users using this view with REST (Invalid password format or unknown hashing algorithm)

@api_view(['POST'])
def register(request):
serializer=UserSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
#user=User.objects.create_user(username=request.data['username'])
#user.set_password(request.data['password']) #hash password
#user.save()
user=User.objects.get(username=request.data['username'])
token=Token.objects.create(user=user) #create token
return Reponse({"token":token.key, "user":serializer.data})
else:
return Response(serializer.errors)

Everything commented is something i tried before

imports:

from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token

User serializer:

class UserSerializer(serializers.ModelSerializer):
class Meta(object):
model= User
fields = ['id','username','password','email']

​

/r/djangolearning
https://redd.it/181xhg4