Posts with #PythonTip

#PythonTip

Public posts on X that use #PythonTip.

Related hashtags

  1. Daily Python Tip 🐍🐧@python_tip
    Use beautiful_date when need to create date/datetime objects in a simple way. pip install beautiful-date from beautiful_date import * >>> d = 5/Mar/2019 BeautifulDate(2019, 3, 5) >>> d[4:13] datetime.datetime(2019, 3, 5, 4, 13) #pythontip from @KuzmovychBox
    21469
  2. Daily Python Tip 🐍🐧@python_tip
    Does your #numpy array contain missing values? > import numpy as np > x = np.array([1,2,3,np.nan]) You can remove them: > x[~np.isnan(x)] array([ 1., 2., 3.]) > np.nanmean(x) 2.0 Or replace them by a number: > np.nan_to_num(x,0) array([ 1., 2., 3., 0.]) #pythontip
    21245
  3. Daily Python Tip 🐍🐧@python_tip
    #Python Best Practices for a 🆕 Project in 2021: pyenv, poetry, VS code, pytest, pytest-cov, pre-commit, flake8, black, mypy, isort Thanks, @Eli_Krumova, for this #pythontip. Do you want to contribute a tip? Send it to or just mention us in your tweet.
    Sourabh Singh Katoch @SourabhSKatoch
    21531
  4. Daily Python Tip 🐍🐧@python_tip
    One more way to combine a list of lists into a single set: >>> lol = [['a', 'b', 'c'], ['b', 'c', 'd'], ['d', 'e']] >>> set().union(*lol) set(['a', 'c', 'b', 'e', 'd']) #pythontip from @raymondh
    01941
  5. Mike Driscoll✓@driscollis
    #PythonTip 🐍🔥 Use `pathlib` to list all the files of a specific type in a folder. Here's an example:
    Download
    41315.3K
  6. Daily Python Tip 🐍🐧@python_tip
    #pythontip by @justmarkham: Did you encounter the dreaded SettingWithCopyWarning in #pandas? 🐼👻 The usual solution is to rewrite your assignment using "loc": ❌ df[df.col == val1].col = val2 ✅ df.loc[df.col == val1, 'col'] = val2 See example 👇
    Download
    1948
  7. Daily Python Tip 🐍🐧@python_tip
    zip() is its own inverse (via @jakevdp): >>> data = [(1, 2, 3), ('a', 'b', 'c')] >>> zipped = zip(*data) >>> zipped [(1, 'a'), (2, 'b'), (3, 'c')] >>> unzipped = zip(*zipped) >>> unzipped [(1, 2, 3), ('a', 'b', 'c')] #pythontip #zip
    036109
  8. Mike Driscoll✓@driscollis
    🐍 #PythonTip: Use list comprehensions for concise and readable one-liners. Example: `[x**2 for x in range(10) if x%2 == 0]` #CodeClean
    64417.6K
  9. Bas Steins✓@bascodes
    💡🐍 Python is a popular language for connecting different data sources. Use a 𝙲𝚑𝚊𝚒𝚗𝙼𝚊𝚙 to get a singular value from a collection of different 𝚍𝚒𝚌𝚝s: #tweet100 #pythontip
    Download
    615109
  10. Daily Python Tip 🐍🐧@python_tip
    Did you know that there is an else clause in Python's `for` loops letting you check if the loop encountered a `break`? Example: 👇👇 #pythontip by @bascodes
    Download
    Bas Steins @bascodes
    Did you know that there is an else clause in Python's `for` loops letting you check if the loop encountered a `break`? #pythontip
    1128
  11. Bas Steins✓@bascodes
    Did you know that there is an else clause in Python's `for` loops letting you check if the loop encountered a `break`? #pythontip
    Download
    017
  12. Daily Python Tip 🐍🐧@python_tip
    Working with a large DataFrame, that is too slow to load/write with read_csv/to_csv? Try read_hdf/to_hdf or read_parquet/to_parquet (For more info: #pythontip #pandas
    0946
  13. Daily Python Tip 🐍🐧@python_tip
    You can name your slices: >>> record = "01234567890123456789I want this0123456789" >>> IWANT = slice(20,31) >>> record[IWANT] 'I want this' #python #pythontip
    12559
  14. pystar@pystar
    #PythonTip Use `itertools.count` to generate a range of floats pretty similar to how you can use `range(start, stop, step)` to generate a range of integers.
    Download
    3851
  15. Show more posts