Sunday, 20 June 2021

MATHEMATICAL FUNCTIONS ON SERIES IN PANDAS [Boolean Functions] - PYTHON PROGRAMMING


1] Greater than

import pandas as pd

s1 = pd.Series([10,20,120,40,150])

s2 = pd.Series([70,80,90,100,110])

s1>(s2)




2] Less than

import pandas as pd

s1 = pd.Series([10,20,120,40,150])

s2 = pd.Series([70,80,90,100,110])

s1<(s2)





3] Equal to

import pandas as pd

s1 = pd.Series([10,20,120,40,150])

s2 = pd.Series([70,20,90,40,110])

s1==(s2)





Join us: https://t.me/jupyter_python 

MATHEMATICAL FUNCTIONS ON SERIES IN PANDAS [Part 1] - PYTHON PROGRAMMING


1] Addition 

#clcoding
import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

 s1.add(s2)







2] Subtraction

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.subtract(s2)




 
3] Multiplication

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.multiply(s2)







4] Division

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.divide(s2)

        
 
                                                                      

   

Join us: https://t.me/jupyter_python

Saturday, 19 June 2021

ATTRIBUTES OF SERIES IN PANDAS - PYTHON PROGRAMMING

ATTRIBUTES OF SERIES IN PANDAS


Index - Series.index - Return all index values
Array - Series.array - Return all index values
Values - Series.values - Return values of series
Name - Series.name - Return the name of Series
Shape - Series.shape - Return the shape
Ndim - Series.ndim - Return the dimension of series
Size - Series.size - Return the size of series
Nbytes - Series.nbytes - Returns the memory occupied
memory-usage - Series.memory-usage() - Returns memory occupied by both index & values






Join us: https://t.me/jupyter_python

Friday, 18 June 2021

How do you find dayname of particular date of year?






#How do you find dayname of particular date of year?

#Clcoding

import calendar as cal

dayname = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 
          'FRIDAY', 'SATURDAY', 'SUNDAY']

inx = cal.weekday(2021,6,18)

dayname[inx]






Join us: https://t.me/jupyter_python Like us: https://www.facebook.com/pirawenpython

Thursday, 17 June 2021

How to make a text in python colorfull.





#how to make a text in python colorfull. 
#clcoding
print("\033[92mIf you like this post, Upvote it")    
print("\033[96mIf you like this post, Upvote it")    
print("\033[93mIf you like this post, Upvote it")    
print("\033[95mIf you like this post, Upvote it")    
print("\033[1mIf you like this post, Upvote it")    
print("\033[4mIf you like this post, Upvote it")    
print("\033[94mIf you like this post, Upvote it")  


Join us: https://t.me/jupyter_python Like us: https://www.facebook.com/pirawenpython

How to use class and method without creating object




#How to use class and method without creating object

#clcoding

class fruit:

    def is_sweet():

        return True
    
if fruit.is_sweet():
        print("Yes")
else:
        print("No")




Join us: https://t.me/jupyter_python

How do you find which string largest between two strings?



#HOW TO WHICH STRING IS LARGEST BETWEEN TWO STRINGS


#clcoding

str1 = 'Clcoding'

str2 = 'ClcodingPython'

max(str1,str2)





#HOW TO WHICH STRING IS LARGEST BETWEEN TWO STRINGS

#clcoding

str1 = 'Clcoding'

str2 = 'ClcodingPython'

if str1>str2:

    print(str1,'is the largest string')

else:

    print(str2,'is the largest string')




Join us: https://t.me/jupyter_python Like us: https://www.facebook.com/pirawenpython

Tuesday, 15 June 2021

Login with Retrofit in android Studio with SourceCode | Login and Registration form in android using JSON example

 Build.gradle File:-  
 
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
implementation 'com.squareup.retrofit2:converter-gson:2.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.6.0'
 
 Activity-main 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/colorWhite"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:text="Login to continue"
android:layout_marginTop="100dp"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:textColor="@color/colorPrimaryDark"
android:layout_height="wrap_content" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_marginTop="30dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:hint="Username"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:inputType="text"
android:id="@+id/edUsername"
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_marginTop="30dp"
android:hint="Password"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:inputType="textPassword"
android:id="@+id/edPassword"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_margin="30dp"
android:text="Login"
android:id="@+id/btnLogin"
android:background="@color/colorPrimary"
android:textColor="@color/colorWhite"
android:layout_height="wrap_content" />
</LinearLayout
 
 Java File :-
 
1. Api Client 
 
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {

private static Retrofit getRetrofit(){

HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build();

Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl("http://api.irawen.net/") //Change server URL
.client(okHttpClient)
.build();

return retrofit;
}


public static UserService getUserService(){
UserService userService = getRetrofit().create(UserService.class);

return userService;
}

}

2. Login Request :-
 
public class LoginRequest {

private String username;
private String password;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}

3. Login response :- 
 
public class LoginResponse {


private int user_id;
private String email;
private String username;

public int getUser_id() {
return user_id;
}

public void setUser_id(int user_id) {
this.user_id = user_id;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
}
 
4. Main Activity :-
 import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.material.textfield.TextInputEditText;

import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {


TextInputEditText username, password;
Button btnLogin;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

username = findViewById(R.id.edUsername);
password = findViewById(R.id.edPassword);
btnLogin = findViewById(R.id.btnLogin);

btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

if(TextUtils.isEmpty(username.getText().toString()) || TextUtils.isEmpty(password.getText().toString())){
Toast.makeText(MainActivity.this,"Username / Password Required", Toast.LENGTH_LONG).show();
}else{
//proceed to login
login();
}

}
});
}


public void login(){
LoginRequest loginRequest = new LoginRequest();
loginRequest.setUsername(username.getText().toString());
loginRequest.setPassword(password.getText().toString());

Call<LoginResponse> loginResponseCall = ApiClient.getUserService().userLogin(loginRequest);
loginResponseCall.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {

if(response.isSuccessful()){
Toast.makeText(MainActivity.this,"Login Successful", Toast.LENGTH_LONG).show();
LoginResponse loginResponse = response.body();

new Handler().postDelayed(new Runnable() {
@Override
public void run() {

startActivity(new Intent(MainActivity.this,DashboardActivity.class).putExtra("data",loginResponse.getUsername()));
}
},700);

}else{
Toast.makeText(MainActivity.this,"Login Failed", Toast.LENGTH_LONG).show();

}

}

@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
Toast.makeText(MainActivity.this,"Throwable "+t.getLocalizedMessage(), Toast.LENGTH_LONG).show();

}
});


}

}

5. User Service :-
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;

public interface UserService {


@POST("authenticate/")
Call<LoginResponse> userLogin(@Body LoginRequest loginRequest);


}

Sunday, 23 May 2021

DIGITAL CLOCK IN PYTHON




#DIGITAL CLOCK IN PYTHON
#clcoding

from datetime import datetime
from time import sleep
while 1:
    n=datetime.now()
    print(datetime.strftime(n,"%H:%M:%S"), end='\r')
    sleep(1) 


Join us: https://t.me/jupyter_python 

Sunday, 2 May 2021

Conversion of Hex, Oct, Bin numbers from integer using python


Code: 

#Convert into HEX
print('{:X}'.format(199))

#Convert into OCT
print('{:o}'.format(199))

#Convert into Binary
print('{:b}'.format(199))

#Convert into Grey
print('{:g}'.format(199))





Join us: https://t.me/jupyter_python

Monday, 26 April 2021

Let’s play with inheritance. What will be outputted?


class A

{

public void abc(int q)

{

Console.WriteLine("abc from A");

}

}

class B : A

{

public void abc(double p)

{

Console.WriteLine("abc from B");

}

}

static void Main(string[] args)

{

int i = 5;

B b = new B();

b.abc(i);

Console.ReadLine();

}

Answer :-

abc from B.

A typical polymorphism understanding swindle. The main thing is not to forget and overlook anything. What will be the result of execution of the following code?


class Program

{

static void Main(string[] args)

{

MyClassB b = new MyClassB();

MyClassA a = b;

a.abc();

Console.ReadLine();

}

}

class MyClassA

{

public MyClassA()

{

Console.WriteLine("constructor A");

}

public void abc()

{

Console.WriteLine("A");

}

}

class MyClassB:MyClassA

{

public MyClassB()

{

Console.WriteLine("constructor B");

}

public void abc()

{

Console.WriteLine("B");

}

}

Answer :-

constructor A
constructor B
A

During initialization of the B class, the constructor of the A class will be executed by default, then constructor of the B class. After assignment of the b value to a type variable of the A class, we will get an instance of the B class in it. One would think that abc() from the B class should be called, but since there is no specification of any predicate of the abc method in the B class, it hides abc from the A class. The example is not quite correct and abc() in the B class will be underlined, since the new predicate is required.

Friday, 23 April 2021

Print Color text in Python

Code: 

#clcoding
print("\033[1;37;48m Python \n")
print("\033[1;36;48m Python \n")
print("\033[1;35;48m Python \n")
print("\033[1;34;48m Python \n")
print("\033[1;33;48m Python \n")
print("\033[1;32;48m Python \n")
print("\033[1;31;48m Python \n")








Join us: https://t.me/jupyter_python

Monday, 29 March 2021

Constructors Part 4 | Static Constructors vs Non Static Constructor |

Static Constructors Vs Non-Static Constructors :

If a constructor is explicitly declared by using a static modifier we call that constructor as static constructor whereas rest of other are non-static constructor only.

Constructors are responsible for initializing fields/variables of a class, static fields are initialized by static constructors and non-static fields are initialized by non-static constructors.

Static constructors are implicitly called whereas non-static constructors must be explicitly called.

Static constructors executes immediately once the execution of a class starts and more over it's the first block of code to run under a class whereas non-static constructors executes only after creating the instance of class as well as each and every time the instance of class is created.

In the life cycle of a class static constructors executes one and only one time whereas non-static constructors executes for zero times if no instances are created and "n" times if "n" instances are created.

 Non-static constructors can be parameterized but static constructors can't have any parameters because  static constructors are implicitly called and more over it's the first block of code to run under class.

Non-static constructors can be overloaded where as static constructors can't be overloaded.

 // C# Program to demonstrate
// how to declare the static
// constructor and non-static
// constructor
using System;
 
class ABC{
   
// Static variable
static int s;
 
// Non-static variable
int ns;
 
// Declaration of
// static constructor
static ABC()
{
    Console.WriteLine("It is static constructor");
}
 
// Declaration of
// non-static constructor
public ABC()
{
    Console.WriteLine("It is non-static constructor");
}
 
// Main Method
static void Main(string[] args)
{
 
    // Static constructor will call implicitly
    // as soon as the class start to execute
    // the first block of code to execute
    // will be static constructor
 
    // Calling non-static constructor
    ABC obj1 = new ABC();
}
}

Output :

It is static constructor
It is non-static constructor

Every class contains an implicit constructor if not defined explicitly and those implicit constructors are defined based on the following criteria :

⟶ Every class except a static class contains an implicit non-static constructor if not defined with an explicit constructors .

⟶ Static constructors are implicitly defined only if that class contains any static fields or else that constructor will not be present at all.

Thursday, 25 March 2021

Constructors in C#.NET Part 3 | Why Constructors are Needed in our class | Clcoding

Every class requires a constructor to be present init if we want to create the instance of that class.

Every class contains an implicit constructor if not defined explicitly and with the help of that implicit constructor instance of class can be created.

What is the need of defining a constructor explicitly again ?

Implicit constructor of a class will initialize variables of a class with the same value even if we create multiple instance of that class.


If we define constructor explicitly with parameters then we get a change of initializing the fields or variables of the class with a new value every time we are going to create instance of that class.

When ever we define a class identify whether if the class variables requires some values to execute and if they are required then define a constructor explicitly and pass values thru that constructor , so that every time the instance of the class is created we get a chance of passing new values.

Note : Generally every class requires some values for execution and the values that is required for a class to execute are always sent to that class by using the constructor only.


Tuesday, 23 March 2021

Types of Constructors in C#.NET Part 2 | C#.NET Tutorial | Clcoding

Type of Constructors 

1. Default or Parameter Less Constructor

2. Parameterized Constructor

3. Copy Constructor

4. Static Constructor

Default or Parameter Less Constructor : 

 If a constructor method doesn't take any parameters then we call that as default or parameter less. these constructors can be defined by a programmer explicitly or else will be default implicitly provided there is no explicit constructor under the class. 

class Test

{

public Test ()     //Implicit Constructor

    {

  }

}


Parameterized Constructor :

If a constructor method is defined with out any parameters we call that as parameterized constructor and these constructor can be defined by the programmers only but never can be defined implicitly.


Copy Constructor :

If we want to create multiple instances with the same values then we use these copy constructors, in a copy constructors the  constructors takes the same class as a parameters to it.

Static Constructor :

If a constructor is explicitly declared by using static modifier we call that as static constructor. All the constructors we have defined till now are non-static or instance constructors.

Class Test

{

static Test ()    //Static constructor defined explicitly

   {

   }

public Test ()   // Implicit default constructor

  {

  }

}


If a class contains any static the only implicit static constructors will be present or else we need to define them explicitly whereas non-static constructors will be implicitly defined in every class (except static class) provided we did not define them explicitly.

Static constructor are responsible in initializing static variables and these constructors are never called explicitly they are implicitly called and more over these constructor are first to execute under any class.

Static constructors can't be parameterized so overloading static constructors is not possible. 

 

Monday, 22 March 2021

Constructors in C#.NET Part 1 | C#.NET Tutorial | Clcoding

It's a special method present under a class responsible for initializing the variable of that class.

The name of a constructor method is exactly the same name of the class in which it was present and more over it's a non-value returning method.

Each and every class requires this constructor if we want to create the instance of that class.

class Test

{

int i ;

Test obj = new Test();  // Valid

⟶ It's the responsibility of a programmer to define a constructor under his class and if he fails to do so, on behalf of the programmer an implicit constructor gets defined in that class by the compiler.

 class Test

{

int i ; string s; bool b;

public Test ()

{

i = 0;  // Initializing the variables

s = null;

b = false;

}

}  

Implicitly defined constructors are parameter less and these constructor are also known as default constructors.

Implicitly defined co0nstructor are public.

We can also defined a constructor under the class and if we define it we can call it as explicit constructor and explicit constructor can be parameter less or parameterized also.

[ < modifiers > ] <Name> ( [ < parameter list > ] )

-Stmts

}

Defining : Implicit or Explicit

Calling : Explicit

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (351) Python Quiz (21) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses