newbie question - df.method() vs method(df)
Hi All,
I'm not new to stats, but I am new to python. Something I'm struggling with is when to use the syntax df.method() versus the syntax method(df).
For example, I see I can get the length of a dataframe with len(df) but not df.len() . I'm sure there's a reason, but I haven't come across it yet! In contrast, I can see the first five lines of a dataframe with df.head() but not head(df) .
What am I missing? I'm using Codecademy, and they totally glossed over this. I've searched for similar posts and didn't see any.
Thanks for your help!
/r/pystats
https://redd.it/1340jbx
Hi All,
I'm not new to stats, but I am new to python. Something I'm struggling with is when to use the syntax df.method() versus the syntax method(df).
For example, I see I can get the length of a dataframe with len(df) but not df.len() . I'm sure there's a reason, but I haven't come across it yet! In contrast, I can see the first five lines of a dataframe with df.head() but not head(df) .
What am I missing? I'm using Codecademy, and they totally glossed over this. I've searched for similar posts and didn't see any.
Thanks for your help!
/r/pystats
https://redd.it/1340jbx
Reddit
r/pystats on Reddit: newbie question - df.method() vs method(df)
Posted by u/TeacherShae - 1 vote and 6 comments
Flask app rendering only base page without extending/dynamic content in all cases.
Please bear with me as I'm a complete beginner in Web Development and recently started Flask.
I have the following code for the app:
@app.route('/', methods='POST','GET')
def index():
if request.method == 'POST':
{stuff}
try:
{stuff}
except youtubetranscriptapi.errors.TranscriptsDisabled:
return rendertemplate('index.html', urlfieldtext="Wrong URL")
{stuff}
return rendertemplate('index success.html')
else:
return rendertemplate('index.html', urlfieldtext="Enter Video url")
The relevant code for index.html page:
<form action="/" method="post" id="details-form">
/r/flask
https://redd.it/133uonp
Please bear with me as I'm a complete beginner in Web Development and recently started Flask.
I have the following code for the app:
@app.route('/', methods='POST','GET')
def index():
if request.method == 'POST':
{stuff}
try:
{stuff}
except youtubetranscriptapi.errors.TranscriptsDisabled:
return rendertemplate('index.html', urlfieldtext="Wrong URL")
{stuff}
return rendertemplate('index success.html')
else:
return rendertemplate('index.html', urlfieldtext="Enter Video url")
The relevant code for index.html page:
<form action="/" method="post" id="details-form">
/r/flask
https://redd.it/133uonp
Reddit
r/flask on Reddit: Flask app rendering only base page without extending/dynamic content in all cases.
Posted by u/_Despaired_ - No votes and 10 comments
Api vs Django views
Hey guys I’m a beginner in Django and I’m wondering is DRF api development an alternative to using default django views or are they completely different concepts? If they are different, when do I use DRF exactly?
/r/django
https://redd.it/1343dh5
Hey guys I’m a beginner in Django and I’m wondering is DRF api development an alternative to using default django views or are they completely different concepts? If they are different, when do I use DRF exactly?
/r/django
https://redd.it/1343dh5
Reddit
r/django on Reddit: Api vs Django views
Posted by u/thepragprog - 2 votes and 2 comments
Monday Daily Thread: Project ideas!
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/13472vn
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/13472vn
Reddit
r/Python on Reddit: Monday Daily Thread: Project ideas!
Posted by u/Im__Joseph - 4 votes and no comments
Releasing code-genie => Copilot for Jupyter Notebooks!
Engineers have increased their productivity by 50% using GitHub copilot. Why should data scientists be left behind?
Here's a jupyter notebook to help you get started!
/r/JupyterNotebooks
https://redd.it/133lm6p
Engineers have increased their productivity by 50% using GitHub copilot. Why should data scientists be left behind?
Here's a jupyter notebook to help you get started!
/r/JupyterNotebooks
https://redd.it/133lm6p
GitHub
code-genie/Starter.ipynb at main · thismlguy/code-genie
convert text descriptions into python callable. Contribute to thismlguy/code-genie development by creating an account on GitHub.
What are some of the best python talks to (re)watch?
Recently i have been looking around for cool/good talks about python and found some things that i thought were super interesting like
https://realpython.com/must-watch-pycon-talks/#9-solve-your-problems-with-sloppy-python
https://www.youtube.com/watch?v=YY7yJHo0M5I
https://www.youtube.com/watch?v=sPiWg5jSoZI
but most of these are already a bit older.
Do any of you have interesting talks you can recommend?
/r/Python
https://redd.it/133ztzc
Recently i have been looking around for cool/good talks about python and found some things that i thought were super interesting like
https://realpython.com/must-watch-pycon-talks/#9-solve-your-problems-with-sloppy-python
https://www.youtube.com/watch?v=YY7yJHo0M5I
https://www.youtube.com/watch?v=sPiWg5jSoZI
but most of these are already a bit older.
Do any of you have interesting talks you can recommend?
/r/Python
https://redd.it/133ztzc
Realpython
Top 10 Must-Watch PyCon Talks – Real Python
Get the inside scoop on the top 10 must-watch PyCon talks for both beginners and advanced Python developers. There's something for everyone in this list of informative videos!
Adding Virtual Environments to Git Repo
At work, the engineer in charge of writing python automation tests includes venvs (both linux and windows) in the git repo. His reasoning is that people will have to download the specific python version we are using to the write code anyways; this way when we select the interpreter (which should already be symlinked to the default global python interpreter) all the packages we use will already be available (and auto-updated if necessary when rebasing).
This rubs me the wrong way, I still assume the best and most pythonic way of working is to create your own local environment and installing the packages using a requirements.txt file, possibly adding a git hook to automatically call pip install every time you rebase.
What do you guys think?
/r/Python
https://redd.it/133y7ij
At work, the engineer in charge of writing python automation tests includes venvs (both linux and windows) in the git repo. His reasoning is that people will have to download the specific python version we are using to the write code anyways; this way when we select the interpreter (which should already be symlinked to the default global python interpreter) all the packages we use will already be available (and auto-updated if necessary when rebasing).
This rubs me the wrong way, I still assume the best and most pythonic way of working is to create your own local environment and installing the packages using a requirements.txt file, possibly adding a git hook to automatically call pip install every time you rebase.
What do you guys think?
/r/Python
https://redd.it/133y7ij
Reddit
r/Python on Reddit: Adding Virtual Environments to Git Repo
Posted by u/skeleton_5 - 236 votes and 122 comments
Made a Free Proxy Rotator library
Hello there,
I made a free proxy rotator library that scrapes and validates proxies from freely available sources and rotates them. Integrates well with requests library. Should be helpful for web scraping. Check it out at https://github.com/sachin-sankar/swiftshadow.
/r/Python
https://redd.it/134jgiu
Hello there,
I made a free proxy rotator library that scrapes and validates proxies from freely available sources and rotates them. Integrates well with requests library. Should be helpful for web scraping. Check it out at https://github.com/sachin-sankar/swiftshadow.
/r/Python
https://redd.it/134jgiu
GitHub
GitHub - sachin-sankar/swiftshadow: Free IP Proxy rotator library for python
Free IP Proxy rotator library for python. Contribute to sachin-sankar/swiftshadow development by creating an account on GitHub.
Elegantly Handle Environment Variables in Python with Pydantic
https://medium.com/@dreamferus/elegantly-handle-environment-variables-in-python-with-pydantic-452aae26f34?sk=3a6024cd1c5ea862e4ee18e5468f9941
/r/Python
https://redd.it/134g767
https://medium.com/@dreamferus/elegantly-handle-environment-variables-in-python-with-pydantic-452aae26f34?sk=3a6024cd1c5ea862e4ee18e5468f9941
/r/Python
https://redd.it/134g767
Medium
Elegantly Handle Environment Variables in Python with Pydantic
Typing in Python isn’t a requirement, but when handling input from different sources, it can be a real relief. Environment variables are a…
Monitor flask app for HTTP status codes and access
What are some open sources tools available to monitor my flask app?
Goal is to monitor access, HTTP status codes, etc.
Better if it can be integrated with Grafana or some observability tools out there.
/r/flask
https://redd.it/134sy8o
What are some open sources tools available to monitor my flask app?
Goal is to monitor access, HTTP status codes, etc.
Better if it can be integrated with Grafana or some observability tools out there.
/r/flask
https://redd.it/134sy8o
Reddit
r/flask on Reddit: Monitor flask app for HTTP status codes and access
Posted by u/chimpageek - No votes and no comments
How can we use the MVC pattern in flask?
I am interested in improving my programming in flask and I would appreciate some advice about how to conform to a model-view-controller (MVC) pattern in flask. I am unclear about which of the MVC components map to those that we commonly see in flask (views/routes, models, templates, etc.) and could use some feedback.
I was thinking of creating:
routes.py: where the `@bp.route` decorated functions go
controllers.py: functions that get called by the decorated route functions and bring together the views.py and models.py functionality to return a view to the front-end
views.py: for returning JSON representations and rendering HTML templates ready to hand back to the front end
models.py: for managing database models.
The following is an example - it isn't from a real app and probably won't work as it is. I am just using it to illustrate my thinking:
routes.py:
@peoplebp.route('/api/people')
def getpeople():
return controllers.getpeople()
controllers.py:
def getpeople():
people = models.Person.query.all()
return views.renderpeople(people)
views.py:
def renderpeople(people):
people = p.name for p in people
/r/flask
https://redd.it/134j8qw
I am interested in improving my programming in flask and I would appreciate some advice about how to conform to a model-view-controller (MVC) pattern in flask. I am unclear about which of the MVC components map to those that we commonly see in flask (views/routes, models, templates, etc.) and could use some feedback.
I was thinking of creating:
routes.py: where the `@bp.route` decorated functions go
controllers.py: functions that get called by the decorated route functions and bring together the views.py and models.py functionality to return a view to the front-end
views.py: for returning JSON representations and rendering HTML templates ready to hand back to the front end
models.py: for managing database models.
The following is an example - it isn't from a real app and probably won't work as it is. I am just using it to illustrate my thinking:
routes.py:
@peoplebp.route('/api/people')
def getpeople():
return controllers.getpeople()
controllers.py:
def getpeople():
people = models.Person.query.all()
return views.renderpeople(people)
views.py:
def renderpeople(people):
people = p.name for p in people
/r/flask
https://redd.it/134j8qw
Reddit
r/flask on Reddit: How can we use the MVC pattern in flask?
Posted by u/Emergency-Crab-354 - 5 votes and 8 comments
I'd like to look at well written Django projects.
I'm looking for really well built Django projects so I can analyze file structure and code to derive good practices.
Post some repos please :)
/r/django
https://redd.it/134ko4x
I'm looking for really well built Django projects so I can analyze file structure and code to derive good practices.
Post some repos please :)
/r/django
https://redd.it/134ko4x
Reddit
r/django on Reddit: I'd like to look at well written Django projects.
Posted by u/tea_lion - 25 votes and 10 comments
Flask-Session not working with 2.3 removing sessioncookiename
Like the title says sessioncookiename was removed from 2.3 and Flask-Session uses that, Flask-Session hasn't seen any updates in years so I don't think their gonna fix it on their end. I've seen a fork of it called flask-session2 but don't really know if it's trustworthy. Any ideas?
/r/flask
https://redd.it/1350zrm
Like the title says sessioncookiename was removed from 2.3 and Flask-Session uses that, Flask-Session hasn't seen any updates in years so I don't think their gonna fix it on their end. I've seen a fork of it called flask-session2 but don't really know if it's trustworthy. Any ideas?
/r/flask
https://redd.it/1350zrm
Reddit
r/flask on Reddit: Flask-Session not working with 2.3 removing session_cookie_name
Posted by u/Total_Adept - No votes and 1 comment
404 Errors from simple API project
Hi All,
Currently learning the basics of flask. Have got a local server up and running, but whenever I send it a get request I get a 404 error. Any idea of where Im going wrong here?
get request: http://127.0.0.1:5000/hello
from flask import Flask
from flaskrestful import Api, Resource
app = Flask(name)
api = Api(app)
class HelloWorld(Resource):
def get(self):
data={"data":"Hello World"}
return data
api.addresource(HelloWorld,'/hello')
if name=='main':
app.run(debug=True)
​
/r/flask
https://redd.it/134wssk
Hi All,
Currently learning the basics of flask. Have got a local server up and running, but whenever I send it a get request I get a 404 error. Any idea of where Im going wrong here?
get request: http://127.0.0.1:5000/hello
from flask import Flask
from flaskrestful import Api, Resource
app = Flask(name)
api = Api(app)
class HelloWorld(Resource):
def get(self):
data={"data":"Hello World"}
return data
api.addresource(HelloWorld,'/hello')
if name=='main':
app.run(debug=True)
​
/r/flask
https://redd.it/134wssk
Reddit
r/flask on Reddit: 404 Errors from simple API project
Posted by u/yewstreet - 1 vote and 12 comments
Use AWS Elasticache Redis as Celery Broker?
So we're using AWS to deploy our project, and using Celery for Event Driven Architecture, so celery workers are always up and running.
We wanted to use Redis as a broker, since SQS has no monitoring support from either Celery or Celery Flower. We tried using AWS MemoryDB Redis as broker, but were unsuccessful as Celery at the moment does not support clustered Redis architecture. So now we're using Elasticache Redis as the broker, but the AWS docs says that Elasticache is not persistent, and data loss might occur if the primary node fails, which means that some messages might be lost which would be really hard to recover.
So my question is that is Elasticache is a wise choice for using Redis as a broker, or we should look at something else?
Also, if someone here has used Elasticache Redis as their celery broker, please let me know your experience and if you would recommend it.
/r/django
https://redd.it/134z8ly
So we're using AWS to deploy our project, and using Celery for Event Driven Architecture, so celery workers are always up and running.
We wanted to use Redis as a broker, since SQS has no monitoring support from either Celery or Celery Flower. We tried using AWS MemoryDB Redis as broker, but were unsuccessful as Celery at the moment does not support clustered Redis architecture. So now we're using Elasticache Redis as the broker, but the AWS docs says that Elasticache is not persistent, and data loss might occur if the primary node fails, which means that some messages might be lost which would be really hard to recover.
So my question is that is Elasticache is a wise choice for using Redis as a broker, or we should look at something else?
Also, if someone here has used Elasticache Redis as their celery broker, please let me know your experience and if you would recommend it.
/r/django
https://redd.it/134z8ly
Reddit
r/django on Reddit: Use AWS Elasticache Redis as Celery Broker?
Posted by u/Deadpool5551 - 3 votes and 3 comments
Rendering child templates with context
I am using class based views and my problem is that I have a base template for cards, which provides the styling and functionality for them. I also have multiple card view classes (Card1, Card2, etc) which each have context, and set the template_name to the base template for the cards. I want to be able to call each card class inside my home template, instead of using {% include BaseCardTemplate with..... %} because there is a lot of context. Is there a standard Django way to do this?
​
And if there is a standard way to do this in Django is it also applicable including templates that rely on models? For example if I have a button that when clicked, I want to display a window that gets its information from the app's model using the button's data attribute as the primary key, how is this done?
/r/django
https://redd.it/1352tte
I am using class based views and my problem is that I have a base template for cards, which provides the styling and functionality for them. I also have multiple card view classes (Card1, Card2, etc) which each have context, and set the template_name to the base template for the cards. I want to be able to call each card class inside my home template, instead of using {% include BaseCardTemplate with..... %} because there is a lot of context. Is there a standard Django way to do this?
​
And if there is a standard way to do this in Django is it also applicable including templates that rely on models? For example if I have a button that when clicked, I want to display a window that gets its information from the app's model using the button's data attribute as the primary key, how is this done?
/r/django
https://redd.it/1352tte
Reddit
r/django on Reddit: Rendering child templates with context
Posted by u/JayaRobus - 1 vote and 3 comments
GeoDjango resources/ materials
May I please ask if you have any materials or resources on geoDjango that you would be willing to share? I am looking to expand my knowledge on this topic and any help would be greatly appreciated. Thank you!
/r/django
https://redd.it/134qcy5
May I please ask if you have any materials or resources on geoDjango that you would be willing to share? I am looking to expand my knowledge on this topic and any help would be greatly appreciated. Thank you!
/r/django
https://redd.it/134qcy5
Reddit
r/django on Reddit: GeoDjango resources/ materials
Posted by u/NoHistorian4672 - 3 votes and 1 comment
Tuesday Daily Thread: Advanced questions
Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.
If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/1355kwt
Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.
If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/1355kwt
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
Load template tags inside model
I have html inside a body = model.TextField and with {{ body | safe }} i get the html code rendern but i would like to load Django template tags inside for images.
Any tips? I have not found a built-in template tag that support this.
/r/django
https://redd.it/134zin1
I have html inside a body = model.TextField and with {{ body | safe }} i get the html code rendern but i would like to load Django template tags inside for images.
Any tips? I have not found a built-in template tag that support this.
/r/django
https://redd.it/134zin1
Reddit
r/django on Reddit: Load template tags inside model
Posted by u/to_sta - 2 votes and 1 comment