3/1/2023 0 Comments Python code snippets![]() ![]() Parse_dates: Convert Columns into Datetime When Using Pandas to Read CSV Filesįilter Rows only if Column Contains Values from another List Set_categories in pandas: Sort Categorical Column by a Specific Ordering Pd.Series.str: Manipulate Text Data in a pandas Series Pd.Series.map: Change Values of a Pandas Series Using a Dictionary : Apply Different Aggregations to Different ColumnsĭataFrame.pipe: Increase the Readability of your Code when Applying Multiple Functions to a DataFrame Pd.DataFrame.agg: Aggregate over Columns or Rows Using Multiple Operations Print error without stopping the for loop in PythonĬoncurrently execute tasks on separate CPUsĬompare the execution time between 2 functions Save Immediate Output when an Error Occurs Underscore “_”: Ignore the index in Python for loops Underscore(_): Ignore values that will not be used How to Execute Shell Commands in a Python ScriptĪrgparse: Python Library to Parse Arguments from Command Line Warnings: Ignore Warnings when Running Python Code _main_.py: Run a Directory like a Main ScriptĪssert in Python: Output a Customized Message When the Assertion Fails How to Improve the Readability of your JSON file using Indent Path.parents: Get the Parent Directory of a File ![]() Pathlib: Iterate Over All Files that End with ‘.csv’ in a Directory Pathlib: Create, Write, and Rename Files in One Line of Code Property Decorator: A Pythonic Way to Use Getters and Setters Static method: use the function without adding the attributes required for a new instance _call_: You can Call your Class Instance like a Function. Getattr: a Better Way to Get the Attribute of a Class Singledispatch: Call Another Function Based on the Type of the Current Function’s ArgumentĪbstract Classes: Declare Methods without ImplementationĬlassmethod: What is it and When to Use it Return Multiple Values from a Function Using Python Dictionaryįunctools.partial: Generate a New Function with Fewer Arguments **kwargs: Pass multiple arguments to a function in Python Use Python Built-in Functions to Speed your Code *iterator: Pass Values of an Iterator to a Function Slice: Make your Indices more Readable by Naming your Sliceĭefaultdict: Return a default value when a key is not availableĭefaultdict: Create a Dictionary with Values that are Listĭatetime + timedelta: Calculate End DateTime based on Start DateTime and Duration Namedtuple: A Lightweight Python Structure to Mange your Data Why Should you Rewrite a For-Loop as a List Comprehension? Map method: Apply a Function to Each Item of an Iterable Set Difference: Find the Difference Between 2 Setsĭifference between list append and list extend Set.intersection: Find the Intersection Between 2 Sets Itertools.islice: Get Items From an Iterable That are Within a Certain Range With a Specific Incrementation Itertools.product: Nested For-Loops in a Generator Expression binations: A better way to iterate through a pair of values in a Python list Stop using = operator to create a copy of a Python list. Zip Function: Create Pairs of Elements from Two Lists in Python Zip: Associate Elements from Two Iterators based on the OrderĬollections.Counter: Count the Occurrences of Items in a List ![]() Join method: Turn an Iterable into a Python String Heapq: Find n Max Values of a Python List Random.sample: Get n Random Elements From a Listįilter: Get the Elements of an Iterable that a Function Returns True Random.choice: Get a Randomly Selected Element from a Python List Re.sub: Replace One String with Another String Using Regular ExpressionĪny: Check if Any Element of an Iterable is TrueĮxtended Iterable Unpacking: Ignore Multiple Values when Unpacking a Python Iterable String find: Find the Index of a Substring in a Python StringĮval: Turn a Python String into a Variable or Function _str_ and _repr_: Create a String Representation of a Python Object Get a Division, Floor Division, And The Remainder of a Division in Pythonīoolean Operators: Connect Two Boolean Expressions into One Expression How to Use Underscores to Format Large Numbers in Python Contentsįractions: Get Numerical Results in Fractions instead of Decimals To get access to these daily tips on the command line, install python-snippet. You can receive these daily tips in your mailbox for free by subscribing to the website. Source code of Python and data science snippets posted daily at Data Science Simplified. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |