Huskies Get a Surprise

https://theawesomer.com/photos/2022/01/huskies_tennis_balls_t.jpg

Huskies Get a Surprise

Link

My Mountain Husky filled up his living room with 2,000 tennis balls then headed out to see how his huskies would react when he left them alone. The normally vocal dogs were speechless at the sight of their newfound paradise but were equally concerned about where their dad went.

The Awesomer

Watch: Mike Rowe, Tim Pool Answer Important Question: Could Liberals Survive a Zombie Apocalypse?

https://www.louderwithcrowder.com/media-library/image.png?id=28796666&width=980

You had to know that when Mike Rowe took a trip to visit Tim Pool, things were going to get a little weird. Or "sporty," as you’re about to hear Rowe say. Not as weird as having the police show up at your house in the middle of a live stream. But still a little out there. They could have discussed the pandemic and Biden’s incompetent response to the pandemic. Or discuss much more pressing matters. Such as, in the event of an apocalypse–full-blown zombies and stuff–who would fair better: liberals or conservatives?

The answer is obvious. But let’s see how they work it out.


Leftists Will NOT Survive The Apocalypse, Mike Rowe Weighs In

youtu.be

Tim Pool believes liberals won’t survive the apocalypse because people in cities won’t know how to survive. They lack hunting skills. People who are more rural will probably fare better. Starbucks hippies aren’t going to do so well when the -ish hits the fan. Guys who know how to farm will. That’s a fair assessment.

Mike Rowe doesn’t say what he feels straight-up. But here’s how he lays out both sides. It’s "Walking Dead" time. You’re gonna have to hunker down in a place with one or two groups of people. Group A are thoughtful writers and thinkers? Group B are hunters, gatherers, and builders? When things get "sporty," what side do you choose?

Rowe and Pool went on to have an interesting conversation about how things are made and the importance of making sure everything is working to make sure those things are made. This is where the incompetence of the Biden administration comes in. Pour a cup of coffee. Listen. Enjoy.

I’ll be over here scripting George A. Romero’s Podcast of the Dead starring Tim Pool and Mike Rowe. I smell money.

Get your content free from Big Tech’s filter. Bookmark this website and sign up for our newsletter!


Crowder Reacts LIVE to Rand Paul OWNING Dr. Fauci! | Louder With Crowder

youtu.be

Louder With Crowder

45 New Laravel Tips 2022 [VIDEO]

We continue compiling random Laravel tips into a special free repository. In this video, I’m presenting a new PR with 45 new tips and will share random 5 of them.Laravel News Links

Laravel EasyPanel

https://repository-images.githubusercontent.com/310552467/99c0d700-6f9e-11eb-9097-464b25973236

Scrutinizer Code Quality
Build Status

EasyPanel

EasyPanel is a beautiful, customizable and flexible admin panel based on Livewire for Laravel.

EasyPanel screenshots

Features :

  • Easy to install
  • Multi Language
  • RTL and LTR mode
  • Sort Data just with a click
  • Support CKEditor and Persian Font for RTL mode
  • Create CRUD for every model in 1 minute
  • Manage route prefix and addresses
  • A beautiful UI/UX with AdminMart template
  • Add/remove Admins with command line
  • UserProviders and Authentication classes are customizable and you can change them
  • You can create your own routes and customize view and components
  • Manage pagination count
  • Real time validation with Livewire
  • A small and beautiful TODO (You can disable it in config)
  • Create a nice and responsive view based on your data in config file for every CRUDs
  • Strong commands to manage package
  • Custom validation based on config file
  • Ajax search with Livewire in every column which you want

Install:

  1. Install the Package in Laravel project with Composer.
composer require rezaamini-ir/laravel-easypanel
  1. Publish EasyPanel files with one command :
php artisan panel:install

Congrats! You installed the package, follow the Usage section.

Usage:

First you have to define admins then You can create a CRUD for a model.
Follow the doc.

Define Admins

Run this command out to make a user as an admin:

php artisan panel:add [user_id]

To create a super admin you can pass --super option to the command.

For example:

php artisan panel:add 10 --super

To remove an admin you can execute this command:

php artisan panel:remove [user_id]

[user_id] : It’s id of user that you want to make as an admin

These commands use UserProvider class in EasyPanel and You can use your own class instead of that and pass it in config file

Multi Lang

If you want change language of Module You have to pass 2 steps:

1 – copy en_panel.json file in resources/lang and paste it in this folder with your lang name like fr_panel.json then customize it.
File format must have _panel.json suffix, e.g: fr_panel.json, fr is your language like : fa, en, fr, ar, ..

2 – Set your lang in easy panel config file in config/easy_panel.php in lang key, this value must be equal to your suffix language file name in the lang directory, like fr.

TODO

If you need TODO feature you have to publish TODO migration with this command

php artisan panel:migration

It will publish TODO’s migration file then you can migrate the migrations with php artisan migrate.

After pass these steps, You must set todo key in config file to true.

Now you have a TODO inside your panel for each admin.

Config

Base Config

Key Type Description
enable bool Module status
todo bool TODO feature status
rtl_model bool If you want a RTL base panel set it true
lang bool Your default language with this format : **_panel.json which you have to just use ** like en or fa
user_model string Address of User model class
auth_class string Address of user authentication class
admin_provider_class string Address of user provider class
redirect_unauthorized string If user is unauthenticated it will be redirected to this address
route_prefix string Prefix of admin panel address e.g: if set it admin address will be : http://127.0.0.1/admin
pagination_count int Count of data which is showed in read action
lazy_mode bool Lazy mode for Real-Time Validation
actions array List of enabled action which you have created a crud config for them.

CRUD Component methods

Method/Property Return Type Description
create bool Create Action for this model
update bool Update Action for this model
delete bool Delete Action for this model
with_auth bool It will fill user_id key for create and update action with auth()->user()->id
getModel string CRUD Model
searchable array Columns in model table which you want to search in read action
validationRules array Validation rules in create and update action (it uses Laravel validation system)
inputs array Input name as key and Input type as value (for update and create action)
storePaths array Where every files of inputs will store
fields array Every data which you want to show in read action (if data is related on other tables pass it as an array, key is relation name and value is column name in related table)

Examples:

Fields:

    public function fields()
    {
        return ['title', 'image', 'user.name'];
    }

Form Inputs:

    public function inputs()
    {
        return [
            'name' => 'text',
            'email' => 'email',
            'password' => 'password',
            'avatar' => 'file'
        ];
    }
    public function inputs()
    {
        return [
            'title' => 'text',
            'body' => 'ckeditor',
            'photo' => 'file',
            'status' => ['select' => [
                'published' => 'Publish Now!',
                'unpublished' => 'Publish Later..',
            ]],
        ];
    }

Dynamic value from a table

    public function inputs()
    {
        return [
            'title' => 'text',
            'body' => 'ckeditor',
            'photo' => 'file',
            'category' => ['select' => 
                Category::where('active', true)
                    ->get()
                    ->pluck('name', 'id') // [1 => 'IT', 2 => 'History', 2 => 'Medicine']
            ],
        ];
    }

What do we use in this package?

Contribution:

If you feel you can improve our package You are free to send a pull request or submit an issue 🙂

V2 Path

Laravel News Links

30 pandas Commands for Manipulating DataFrames

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2021/10/Pandas-in-Python.jpg

The pandas library makes python-based data science an easy ride. It’s a popular Python library for reading, merging, sorting, cleaning data, and more. Although pandas is easy to use and apply on datasets, it has many data manipulatory functions to learn.

You might use pandas, but there’s a good chance you’re under-utilizing it to solve data-related problems. Here’s our list of valuable data manipulating pandas functions every data scientist should know.

Install pandas Into Your Virtual Environment

Before we proceed, make sure you install pandas into your virtual environment using pip:

pip install pandas

After installing it, import pandas at the top of your script, and let’s proceed.

1. pandas.DataFrame

You use pandas.DataFrame() to create a DataFrame in pandas. There are two ways to use this function.

You can form a DataFrame column-wise by passing a dictionary into the pandas.DataFrame() function. Here, each key is a column, while the values are the rows:

import pandas
DataFrame = pandas.DataFrame({"A" : [1, 3, 4], "B": [5, 9, 12]})
print(DataFrame)

The other method is to form the DataFrame across rows. But here, you’ll separate the values (row items) from the columns. The number of data in each list (row data) must also tally with the number of columns.

MAKEUSEOF VIDEO OF THE DAY
import pandas
DataFrame = pandas.DataFrame([[1, 4, 5], [7, 19, 13]], columns= ["J", "K", "L"])
print(DataFrame)

2. Read From and Write to Excel or CSV in pandas

You can read or write to Excel or CSV files with pandas.

Reading Excel or CSV files

To read an Excel file:

#Replace example.xlsx with the your Excel file path 
DataFrame = DataFrame.read_excel("example.xlsx")

Here’s how to read a CSV file:

#Replace example.csv with the your CSV file path 
DataFrame = DataFrame.read_csv("example.csv")

Writing to Excel or CSV

Writing to Excel or CSV is a well-known pandas operation. And it’s handy for saving newly computed tables into separate datasheets.

To write to an Excel sheet:

DataFrame.to_excel("full_path_of_the_destination_folder/filename.xlsx")

If you want to write to CSV:

DataFrame.to_csv("full_path_of_the_destination_folder/filename.csv")

You can also compute the central tendencies of each column in a DataFrame using pandas.

Here’s how to get the mean value of each column:

DataFrame.mean()

For the median or mode value, replace mean() with median() or mode().

4. DataFrame.transform

pandas’ DataFrame.transform() modifies the values of a DataFrame. It accepts a function as an argument.

For instance, the code below multiplies each value in a DataFrame by three using Python’s lambda function:

DataFrame = DataFrame.transform(lambda y: y*3)
print(DataFrame)

5. DataFrame.isnull

This function returns a Boolean value and flags all rows containing null values as True:

DataFrame.isnull()

The result of the above code can be hard to read for larger datasets. So you can use the isnull().sum() function instead. This returns a summary of all missing values for each column:

DataFrame.isnull().sum()

6. Dataframe.info

The info() function is an essential pandas operation. It returns the summary of non-missing values for each column instead:

DataFrame.info()

7. DataFrame.describe

The describe() function gives you the summary statistic of a DataFrame:

DataFrame.describe()

8. DataFrame.replace

Using the DataFrame.replace() method in pandas, you can replace selected rows with other values.

For example, to swap invalid rows with Nan:

# Ensure that you pip install numpy for this to work 
import numpy
import pandas
# Adding an inplace keyword and setting it to True makes the changes permanent:
DataFrame.replace([invalid_1, invalid_2], numpy.nan, inplace=True)
print(DataFrame)

9. DataFrame.fillna

This function lets you fill empty rows with a particular value. You can fill all Nan rows in a dataset with the mean value, for instance:

DataFrame.fillna(df.mean(), inplace = True)
print(DataFrame)

You can also be column-specific:

DataFrame['column_name'].fillna(df[column_name].mean(), inplace = True)
print(DataFrame)

10. DataFrame.dropna

The dropna() method removes all rows containing null values:

DataFrame.dropna(inplace = True)
print(DataFrame)

11. DataFrame.insert

You can use pandas’ insert() function to add a new column to a DataFrame. It accepts three keywords, the column name, a list of its data, and its location, which is a column index.

Here’s how that works:

DataFrame.insert(column = 'C', value = [3, 4, 6, 7], loc=0)
print(DataFrame)

The above code inserts the new column at the zero column index (it becomes the first column).

12. DataFrame.loc

You can use loc to find the elements in a particular index. To view all items in the third row, for instance:

DataFrame.loc[2]

13. DataFrame.pop

This function lets you remove a specified column from a pandas DataFrame.

It accepts an item keyword, returns the popped column, and separates it from the rest of the DataFrame:

DataFrame.pop(item= 'column_name')
print(DataFrame)

14. DataFrame.max, min

Getting the maximum and minimum values using pandas is easy:

DataFrame.min()

The above code returns the minimum value for each column. To get the maximum, replace min with max.

15. DataFrame.join

The join() function of pandas lets you merge DataFrames with different column names. You can use the left, right, inner, or outer join. To left-join a DataFrame with two others:

#Left-join longer columns with shorter ones
newDataFrame = df1.join([df_shorter2, df_shorter3], how='left')
print(newDataFrame)

To join DataFrames with similar column names, you can differentiate them by including a suffix to the left or right. Do this by including the lsuffix or rsuffix keyword:

newDataFrame = df1.join([df2, rsuffix='_', how='outer') 
print(newDataFrame)

16. DataFrame.combine

The combine() function comes in handy for merging two DataFrames containing similar column names based on set criteria. It accepts a function keyword.

For instance, to merge two DataFrames with similar column names based on the maximum values only:

newDataFrame = df.combine(df2, numpy.minimum)
print(newDataFrame)

Note: You can also define a custom selection function and insert numpy.minimum.

17. DataFrame.astype

The astype() function changes the data type of a particular column or DataFrame.

To change all values in a DataFrame to string, for instance:

DataFrame.astype(str)

18. DataFrame.sum

The sum() function in pandas returns the sum of the values in each column:

DataFrame.sum()

You can also find the cumulative sum of all items using cumsum():

DataFrame.cumsum()

19. DataFrame.drop

pandas’ drop() function deletes specific rows or columns in a DataFrame. You have to supply the column names or row index and an axis to use it.

To remove specific columns, for example:

df.drop(columns=['colum1', 'column2'], axis=0)

To drop rows on indexes 1, 3, and 4, for instance:

df.drop([1, 3, 4], axis=0)

20. DataFrame.corr

Want to find the correlation between integer or float columns? pandas can help you achieve that using the corr() function:

DataFrame.corr()

The above code returns a new DataFrame containing the correlation sequence between all integer or float columns.

21. DataFrame.add

The add() function lets you add a specific number to each value in DataFrame. It works by iterating through a DataFrame and operating on each item.

Related:How to Use For Loops in Python

To add 20 to each of the values in a specific column containing integers or floats, for instance:

DataFrame['interger_column'].add(20)

22. DataFrame.sub

Like the addition function, you can also subtract a number from each value in a DataFrame or specific column:

DataFrame['interger_column'].sub(10)

23. DataFrame.mul

This is a multiplication version of the addition function of pandas:

DataFrame['interger_column'].mul(20)

24. DataFrame.div

Similarly, you can divide each data point in a column or DataFrame by a specific number:

DataFrame['interger_column'].div(20)

25. DataFrame.std

Using the std() function, pandas also lets you compute the standard deviation for each column in a DataFrame. It works by iterating through each column in a dataset and calculating the standard deviation for each:

DataFrame.std()

26. DataFrame.sort_values

You can also sort values ascendingly or descendingly based on a particular column. To sort a DataFrame in descending order, for example:

newDataFrame = DataFrame.sort_values(by = "colmun_name", descending = True)

27. DataFrame.melt

The melt() function in pandas flips the columns in a DataFrame to individual rows. It’s like exposing the anatomy of a DataFrame. So it lets you view the value assigned to each column explicitly.

newDataFrame = DataFrame.melt()

28. DataFrame.count

This function returns the total number of items in each column:

DataFrame.count()

29. DataFrame.query

pandas’ query() lets you call items using their index number. To get the items in the third row, for example:

DataFrame.query('4') # Call the query on the fourth index 

30. DataFrame.where

The where() function is a pandas query that accepts a condition for getting specific values in a column. For instance, to get all ages less than 30 from an Age column:

DataFrame.where(DataFrame['Age'] < 30)

The above code outputs a DataFrame containing all ages less than 30 but assigns Nan to rows that don’t meet the condition. ​​​

Handle Data Like a Pro With pandas

pandas is a treasure trove of functions and methods for handling small to large-scale datasets with Python. The library also comes in handy for cleaning, validating, and preparing data for analysis or machine learning.

Taking the time to master it definitely makes your life easier as a data scientist, and it’s well worth the effort. So feel free to pick up all the functions you can handle.

20 Python Functions You Should Know

The Python Standard Library contains many functions to help with your programming tasks. Learn about the most useful and create more robust code.

Read Next

About The Author

Idowu Omisola
(123 Articles Published)

Idowu is passionate about anything smart tech and productivity. In his free time, he plays around with coding and switches to the chessboard when he’s bored, but he also loves breaking away from routine once in a while. His passion for showing people the way around modern tech motivates him to write more.

More
From Idowu Omisola

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

MUO – Feed

The Complete Guide to User Management in Linux

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2022/01/user-management-on-linux-2.jpg

User account management is one of the many challenges of Linux system administrators. Some of the responsibilities of a system administrator are enabling/disabling user accounts, preserving the home directory, setting user permissions, assigning groups/shells to users, and managing passwords.

Effective control of user accounts is only possible after familiarity with the basics of Linux account management. Hence, this article is a stepping stone towards securing user accounts. It demonstrates how to create, delete and modify user accounts and manage predefined settings or files to build the most suitable and secure environment for Linux users.

How to Add User Accounts in Linux

As a word of precaution, any user who utilizes your Linux machine must have a separate user account. A user account allows you to separate your files in a safe space with the ability to tailor your home directories, path, environment variables, etc.

Before beginning with the creation of a new user, list the available user accounts with the help of the cut command as follows:

cut -d: -f1 /etc/passwd

The simplest way of creating a new user account in Linux is with the help of useradd. This utility offers various parameters to specify additional information while adding a new user. Some of the options are:

  • -c: Adds description/comment to a user account.
    useradd -c "John Wise" john
  • -d: Sets the home directory for the specified user. By default, the useradd command sets it to the username (/home/john), but you can replace it with the directory of your choice as follows:
    useradd -d /mnt/home/john
  • -g: Allows you to set the primary group of a user. The user will be added to a group by default if you don’t add one during the creation process.
  • -G: Adds the user to multiple groups.
    useradd -G juice,apple,linux,tech john
  • -o: Creates a new user account using the UID of an existing user.
  • -p: Used to add an encrypted password to the account. You can also add your password later using the passwd command.
    passwd john
MAKEUSEOF VIDEO OF THE DAY

For instance, here’s how you can use the useradd command and some of the above parameters to add a new user:

useradd -g tech -G apple,linux -s /bin/zsh -c "James Adem" adem

In the user creation process, the aforementioned command performs several actions:

Modify Default User Settings

The useradd command reads the default values from /etc/login.defs, /etc/useradd, and /etc/default/useradd. You can open the files in your favorite text editor in Linux, make and save the appropriate changes before using the command.

You can view some of the settings available inside login.defs using the following command:

cat /etc/login.defs | grep 'PASS\|UID\|GID'

The uncommented lines are keywords with values. For instance, the PASS_MAX_DAYS keyword sets a maximum of 9999 days for password expiration. Similarly, the PASS_MIN_LEN keyword requires the password length to be at least five characters. Lastly, the UID and GID keywords allow customization of the user and group ID ranges for any new user account.

You can also view/modify the default settings present inside the files by using the useradd command with the -D flag.

Note that you don’t use the -D flag to create a new account. Instead, it only allows you to change the default settings. Also, it supports changes for only a few parameters that the useradd command uses to create an account.

Flags Description
-b Modifies the default home directory (/home) for new user accounts.
-g Modifies the default new user primary group (username) with another default group.
-s Replaces the default /bin/bash shell with another default shell.
-e Modifies the default expiration date to disable a user account in YYYY-MM-DD format.
-f Allows to set inactive days before the account is disabled and after password expiration

For instance, the following command changes the default shell to /bin/sh and the home directory to /home/new:

useradd -D -b /home/new -s /bin/sh

Modify User Groups on Linux

usermod is another simple yet straightforward Linux utility to modify user account details. It supports similar parameters or flags as the useradd command and that’s why its usage is quite simple.

For instance, you can change the default shell of the user adem from /bin/sh to /bin/bash as follows:

usermod -s /bin/bash adem

Now to include adem in the sales group, you’ll need to use the -aG flag as a simple -G flag will remove the user from the previously added supplementary groups: apple and linux.

usermod -aG sales adem
cat /etc/group | grep adem

Related: The Best Command Line Utilities for Viewing File Content in Linux

How to Delete User Accounts on Linux

Linux offers another command-line utility userdel to delete any user account. Here’s the basic syntax:

userdel username

However, it will only remove the account details from the /etc/passwd file. To remove the user’s home directory as well, use the -r flag, as follows:

userdel -r username

As a precaution, we recommend finding all the files owned by the user and reassigning them to any other existing user account. Use the find command to list all the files either owned by the user or assigned to a user ID you have removed or not associated with any user.

find / -user username -ls
find / -uid 504 -ls
find / -nouser -ls

Linux User Account Management in a Nutshell

This article demonstrates Linux user account creation, deletion, and modification examples with tips and tricks for any beginner Linux user who wants to pursue system administration and learn user account management.

It also shows how to edit the configuration files to define UID and GID ranges and change the default settings for user account creation in Linux.

How to Add a User in Linux

Need to give a family member or friend access to your Linux PC? Here’s how to add a user in Linux and give them their own account.

Read Next

About The Author

Rumaisa Niazi
(5 Articles Published)

Rumaisa is a freelance writer at MUO. She has worn many hats, from a Mathematician to an Information Security enthusiast, and is now working as a SOC Analyst. Her interests include reading and writing about new technologies, Linux distributions, and anything around Information Security.

More
From Rumaisa Niazi

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

MUO – Feed

Pandas DataFrame Methods equals(), filter(), first(), last(), head(), and tail()

https://blog.finxter.com/wp-content/uploads/2022/01/image-6.png

The Pandas DataFrame has several Re-indexing/Selection/Label Manipulations methods. When applied to a DataFrame, these methods evaluate, modify the elements and return the results.

This is Part 7 of the DataFrame methods series:

  • Part 1 focuses on the DataFrame methods abs(), all(), any(), clip(), corr(), and corrwith().
  • Part 2 focuses on the DataFrame methods count(), cov(), cummax(), cummin(), cumprod(), cumsum().
  • Part 3 focuses on the DataFrame methods describe(), diff(), eval(), kurtosis().
  • Part 4 focuses on the DataFrame methods mad(), min(), max(), mean(), median(), and mode().
  • Part 5 focuses on the DataFrame methods pct_change(), quantile(), rank(), round(), prod(), and product().
  • Part 6 focuses on the DataFrame methods add_prefix(), add_suffix(), and align().
  • Part 7 focuses on the DataFrame methods at_time(), between_time(), drop(), drop_duplicates() and duplicated().
  • Part 8 focuses on the DataFrame methods equals(), filter(), first(), last(), head(), and tail()

Getting Started

💡 Note: To follow along with the examples below, click here to download the finxters.csv file of auto-generated dummy user data. Move this file to the current working directory.

Remember to add the Required Starter Code to the top of each code snippet. This snippet will allow the code in this article to run error-free.

Required Starter Code

import pandas as pd

Before any data manipulation can occur, this library will require installation:

  • The pandas library enables access to/from a DataFrame.

To install these libraries, navigate to an IDE terminal. At the command prompt ($), execute the code below. For the terminal used in this example, the command prompt is a dollar sign ($). Your terminal prompt may be different.

$ pip install pandas

Hit the <Enter> key on the keyboard to start the installation process.

Feel free to check out the correct ways of installing the library here:

If the installations were successful, a message displays in the terminal indicating the same.

DataFrame equals()

The equals() method compares two (2) DataFrames/Series against each other to determine if they have an identical shape and elements. If identical return True, otherwise return False.

The syntax for this method is as follows:

DataFrame.equals(other)
Parameter Description
other A DataFrame or Series to compare.

For this example, we have two (2) DataFrames containing grades for three (3) students.

df_scores1 = pd.DataFrame({'Micah': [91, 58, 73],
                           'Bob':     [53, 87, 46],
                           'Chloe':  [60, 54, 61]})
  
df_scores2 = pd.DataFrame({'Micah': [91, 58, 73],
                           'Bob':     [53, 87, 46],
                           'Chloe':  [60, 54, 61]})
  
result = df_scores1.equals(df_scores2)
print(result)
print(df_scores1.shape)
print(df_scores2.shape)
  • Line [1-2] creates two (2) DataFrames.
  • Line [3] compares df_scores1 against df_scores2 testing the shape and elements. The outcome saves to result (True/False).
  • Line [4] outputs the result to the terminal.
  • Line [5-6] confirms the shape of the DataFrames is equal by outputting the results to the terminal.

Output:

True
(3, 3)
(3, 3)

DataFrame filter()

The filter() method returns a subset of a DataFrame/Series rows/columns based on index label(s). This method does not filter a DataFrame/Series on the contents. The filter applies to the specific label(s) of the selected index. The return value is a subset of the callable.

The syntax for this method is as follows:

DataFrame.filter(items=None, like=None, regex=None, axis=None)
Parameter Description
items A filter list of columns to include in the result.
like A filter string of columns (ex: like='FID') to include in the result.
regex A regex string to filter columns (ex: regex='e$') to include in the result.
axis If zero (0) or index is selected, apply to each column. Default is None. If one (1) is selected, apply to each row.

For this method, various scenarios below highlight its capabilities.

This example uses the items parameter to filter the DataFrame and return the result.

Code – Example 1:

df_fxs = pd.read_csv('finxters.csv')
result = df_fxs.filter(items=['Username', 'Rank'])
print(result.head())
  • Line [1] reads in the comma-separated CSV file and saves it to df_fxs.
  • Line [2] filters df_fxs to include only the columns matching the item labels (Username and Rank). These columns (and associated values) save to result.
  • Line [3] outputs the first five (5) rows (head()) to the terminal.

Output:

  Username Rank
0 wildone92            Authority
1 AmyP             Beginner
2 1998_pete      Basic Knowledge
3 TheCoder  Experienced Learner
4 AliceM Authority

This example uses the like parameter to filter the DataFrame and return the result.

Code – Example 2:

df_fxs = pd.read_csv('finxters.csv')
result = df_fxs.filter(like='FID', axis=1)
print(result.head())
  • Line [1] reads in the comma-separated CSV file and saves it to df_fxs.
  • Line [2] filters df_fxs to include only the columns matching the like label ('FID'). This column (and associated values) save to result.
  • Line [3] outputs the first five (5) rows (head()) to the terminal.

Output:

  FID
0 30022145
1 30022192
2 30022331
3 30022345
4 30022359

This example uses the regex parameter to filter the DataFrame and return the result.

Code – Example 3

df_fxs = pd.read_csv('finxters.csv')
result = df_fxs.filter(regex='e$', axis=1)
print(result.head())
  • Line [1] reads in the comma-separated CSV file and saves it to df_fxs.
  • Line [2] filters df_fxs to include only the columns matching the regex label (First_Name, Last_Name and Username). These columns (and associated values) save to result.
  • Line [3] outputs the first five (5) rows (head()) to the terminal.

Output:

  First_Name Last_Name Username
0 Steve   Hamilton  wildone92
1 Amy  Pullister       AmyP
2 Peter       Dunn  1998_pete
3 Marcus   Williams   TheCoder
4 Alice    Miller    AliceM

Note: Each column name in the output ends with the letter e.

DataFrame first()

The first() method retrieves and returns the first set number of rows (periods) based on the value entered. The index must be a date value to return the appropriate results.

The syntax for this method is as follows:

DataFrame.first(offset)
Parameter Description
offset This parameter is the date period of the data to display (ex: 1M, 2D).

For this example, the blood pressure for three (3) patients over a two (2) month period is retrieved.

r = pd.date_range('2021-01-01', periods=3, freq='1M')
df = pd.DataFrame({'Patient-1': [123, 120, 144], 
                   'Patient-2': [129, 125, 90],
                   'Patient-3': [101, 95,  124]},index=r)

result = df.first('1M')
print(result)
  • Line [1] sets up the following:
    • The date range start date ('2021-01-01').
    • The number of periods (3).
    • The frequency ('1M'). This statement equates to 1 Month.
  • Line [2] creates a DataFrame containing:
    • Three (3) patient names containing three (3) elements of data for each patient.
  • Line [3] saves the first month period to result.
  • Line [4] outputs the result to the terminal.

Output:

  Patient-1  Patient-2  Patient-3
2022-01-31        123        129        101
2022-02-28        120        125         95

💡 Note: The date range for the selected frequency references the last day of the month.

DataFrame last()

The last() method retrieves and returns the last set number of rows (periods) based on the value entered. The index must be a date value for this method to return the expected results.

The syntax for this method is as follows:

DataFrame.last(offset)
Parameter Description
offset This parameter is the date period of the data to display (ex: 1M, 2D).

For this example, the blood pressure for three (3) patients over a  two (2) month period is retrieved.

r = pd.date_range('2021-01-01', periods=3, freq='1M')
df = pd.DataFrame({'Patient-1': [123, 120, 144], 
                   'Patient-2': [129, 125, 90],
                   'Patient-3': [101, 95,  124]},index=r)

result = df.last('1M')
print(result)
  • Line [1] sets up the following:
    • The date range start date ('2021-01-01').
    • The number of periods (3).
    • The frequency ('1M'). This statement equates to 1 Month.
  • Line [2] creates a DataFrame containing:
    • Three (3) patient names containing three (3) elements of data for each patient.
  • Line [3] saves the output to result.
  • Line [4] outputs the result to the terminal.

Output:

  Patient-1  Patient-2  Patient-3
2022-03-31        144 90 125

💡 Note: The date range for the selected frequency references the last day of the month.

DataFrame head() and tail()

These methods display n numbers of records (top or bottom). These methods are useful when you are accessing large amounts of data.

If no parameter is entered, by default, five (5) rows display.

  • The head() method returns the top five (5) rows of the DataFrame.
  • The tail() method returns the bottom five (5) rows of the DataFrame

If a parameter is entered in one of the above methods, n number of rows (top/bottom) will display.

As you will note, the head() method was accessed many times during this article. Both methods are must-haves in your knowledge base.

The syntax for these methods is as follows:

DataFrame.head(n=5)
DataFrame.tail(n=5)
Parameter Description
n An integer value indicating the number of rows to display. By default, five (5) rows display.

For this example, the first five (5) records from the DataFrame and the last five (5) records (tail) from the same DataFrame display.

df_fxs = pd.read_csv('finxters.csv')
print(df_fxs.head())
print(df_fxs.tail())

Output:

Finxter

Performance tips for Laravel

https://madewithlove.com/static/6649432301f833e8feabf4984fd5d3ae/laravel-performance-1.jpgThis is a story from the trenches on how we optimized the performance of a Laravel application using Eloquent.Laravel News Links