Python

7643 readers
37 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
376
 
 

Hi, When im working with some big dataframes and I need to create some columns based on functions. So i have some code like this

Def function(row): function

And then I run the function on the df as

df['new column'] = df.apply(function, axis=1)

But I do this with 10 or more columns/functions at time. I don't think this is efficient because each time a column is created it had to parce the entire data frame. There's a way to create all the columns at the same time while parsing the rows only once?

Thanks for any help.

377
19
Python 3.11.7 is now available (pythoninsider.blogspot.com)
submitted 2 years ago* (last edited 2 years ago) by mac@programming.dev to c/python@programming.dev
 
 

Major new features and changes:

  • PEP 657 – Include Fine-Grained Error Locations in Tracebacks
  • PEP 654 – Exception Groups and except*
  • PEP 673 – Self Type
  • PEP 646 – Variadic Generics
  • PEP 680 – tomllib: Support for Parsing TOML in the Standard Library
  • PEP 675 – Arbitrary Literal String Type
  • PEP 655 – Marking individual TypedDict items as required or potentially-missing
  • bpo-46752 – Introduce task groups to asyncio
  • PEP 681 – Data Class Transforms
  • bpo-433030– Atomic grouping ((?>…)) and possessive quantifiers (*+, ++, ?+, {m,n}+) are now supported in regular expressions. The Faster Cpython Project is already yielding some exciting results. Python 3.11 is up to 10-60% faster than Python 3.10. On average, we measured a 1.22x speedup on the standard benchmark suite. See Faster CPython for details.
378
379
380
 
 

Made a Mastodon bot using Mastodon.PY and I'm so happy it works! 😅

I just got this random idea in my head and decided to see if I could create it, so I built a working slots that uses the 4 image uploads to show the results. It will automatically grant you 10000 Coins the first time and playing costs 50 coins per play. The prices go from 25 to 750, every play adds 25 into the jackpot that starts at 500 when it gets won and 4 jokers will give jackpot. It will say the results in text too and it saves all wallet-amounts to file too which it can load back on restart however it gets killed. 😅

Sorry, just wanted to share this somewhere. 😅 I hope it's fine here.

I am however not really promoting it, not even sure how it will do under pressure (probably get throttled by Mastodon eventually) and it might either stop working or switch account to one of it's own (it's currently just using a personal infobot for testing) depending how it goes... I'm assuming if I give it a 5 plays per day per user limit it could be manageable... 🤷‍♂️

(If you still want to try it, please do not abuse or spam it or I will have to take it offline, but the command to play on Mastodon is: "@infobot@fed.ggtm.eu !slots"

Anyway, thanks for reading about my victory! 😅

381
15
submitted 2 years ago* (last edited 2 years ago) by SpaceTurtle224@lemmy.world to c/python@programming.dev
 
 

Hello, im looking for some beginer-intermediate knowledge in python. I'm interested in more text rather than video based courses preferably with exersises.

382
383
384
6
submitted 2 years ago* (last edited 2 years ago) by jnovinger@programming.dev to c/python@programming.dev
 
 

As seen in https://news.ycombinator.com/item?id=38561682

Memray tracks and reports memory allocations, both in Python code and in compiled extension modules.

385
 
 

cross-posted from: https://programming.dev/post/6990204

Richard McElreath has made his course materials available on GitHub.

However, the course follows the 2nd edition of McElreath's book Statistical Rethinking which is not available in a free digital format.

After watching the first lecture in the Statistical Rethinking 2023 YouTube Playlist, I might go ahead and purchase the text and use this course instead of Trevor Hastie and Rob Tibshirani's An Introduction to Statistical Learning (with Applications in R or Python) course.

I also like that this resource has made an explicit attempt to provide code examples in Julia as well as the more popular Python and R.

I wasn't sure who Richard McElreath was so I did a quick search which revealed his position as Director of the Department of Human Behavior, Ecology and Culture at the Max Planck Institute for Evolutionary Anthropology in Leipzig.

386
 
 

cross-posted from: https://programming.dev/post/6942085

Book (Free)

The resource on statistical methods recommended to me the most has been An Introduction to Statistical Learning (with Applications in R or Python) by Gareth James, Daniela Witten, Trevor Hastie, Rob Tibshirani, and Jonathan Taylor. Its free to download and has been kept up to date. (The latest edition is from 2022.)

Online Course (Free with optional payment for "Verified Track")

For those that prefer a structured online course StanfordOnline: Statistical Learning with R by Trevor Hastie and Robert Tibshirani uses An Introduction to Statistical Learning (with Applications in R) as the course textbook.

More In-Depth Book

Individuals with advanced training in the mathematical sciences may wish to use The Elements of Statistical Learning (Data Mining, Inference, and Prediction) by Trevor Hastie, Robert Tibshirani, and Jerome Friedman which provides a more comprehensive and detailed treatment of a wider range topics in statistical learning.

387
 
 

A new, larger revision of the written content to cover the releases of Flask 3.0 and SQLAlchemy 2.0 (Yes, technically I'm releasing this update a month before 2024, in December 2023)

388
 
 

i was trying to parse a string with pyparsing so all the words were separated from the punctuation signs, i was using this expression to do it:

OneOrMore(Word(alphanums)) + OneOrMore(Char(printables))

But when i parse the following string with this expression:

return abc(1, ULLONG_MAX)

All the words inside the parentheses get split:

['return', 'abc', '(', '1', ',', 'U', 'L', 'L', 'O', 'N', '_', 'M', 'A', 'X', ')', ';']

But if i use this expression:

OneOrMore(Word(alphanums)) + OneOrMore(Char(string.punctuation))

Only a part of the string gets parsed:

['return', 'abc', '(']

What is wrong with those expressions?

389
 
 

Python's standard logging API violates PEP-8 and this #PEP proposes to fix this. Feedback and criticism of all sort is welcome.

390
391
 
 

I'm pretty new to Python and discovered the nicely presented PEP8 coding style guide linked in the post. Stumbling onto The Hitchhiker’s Guide to Python! has been a very helpful compliment to the official Python Documentaion

Hopefully this post will help others getting familiar with Python.

392
 
 

cross-posted from: https://programming.dev/post/6470590

This looks like a great starting point for people with little to no experience with programming to learn to program using Python.

Everything taught by futurecoder.io can be used locally on your own computer. But futurecoder.io doesn't show you how to install Python on your machine but you can fill in that gap with the information provided @ https://wiki.python.org/moin/BeginnersGuide/Download

Other resources are provided on the python.org Beginners Guide if needed.

393
394
395
 
 

any Insomnia alternatives which are not Postman? I need rest and graphql support.
Insomnia is getting worse and worse and I'm worried it won't be better.
#programming @python @golang
@opensource

396
397
398
399
400
 
 

Let's say I have the following structure:

my_module/
  __init__.py
  utilities.py

and __init__.py contains

from .utilities import SomeUtilityFunction

Is there a way to prevent or alert developers when they do

from my_module.utilities import SomeUtilityFunction

instead of

from my_module import SomeUtilityFunction

The problem arose when a few modules started using a function that was imported inside a module in which it wasn't used, while also being available on the module's __init__.py, so after linting the file and removing the unused import my tests started failing.

any other advice for situations like this?

view more: ‹ prev next ›