Wednesday 23 June 2021

HANDLING MISSING DATA (FillNa) IN PANDAS



Firstly, we are importing an excel sheet as a DataFrame,
 

import pandas as pd
ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
dt = pd.DataFrame(ds)
print(dt)








Now, Let's perform some operations related to FillNa()











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

HANDLING MISSING DATA (dropna) IN PANDAS


Firstly, we are importing an excel sheet as a DataFrame,
 

import pandas as pd
ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
dt = pd.DataFrame(ds)
print(dt)






Now, Let's perform some operations related to DROPNA


















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

ILOC[ ] IN PANDAS - PYTHON

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

dt = pd.DataFrame(ds)






Now, Let's perform some operations related to ILOC 












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

LOC[ ] IN PANDAS - PYTHON



LOC[ ] IN PANDAS

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

dt = pd.DataFrame(ds)







Now, Let's perform some operations related to LOC and ILOC 














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

Tuesday 22 June 2021

EXPORT DATAFRAME TO EXCEL, CSV & TEXT FILE IN PANDAS || SAVE DATAFRAME IN PANDAS

EXPORT DATAFRAME TO EXCEL, CSV & TEXT FILE IN PANDAS 

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

st = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

sd = pd.DataFrame(st)

print(st)



Making some changes in the dataframe


st['Total']=st['Hindi']+st['English'] +st['Science'] +st['History']+st['Mathematics']






Now, exporting the DataFrame as Excel, CSV and Text File


sd.to_excel("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.xlsx")

sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.csv")

sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.txt" ,sep = "\t")





As you can see we have created three new files.






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

SORTING DATAFRAME (BY COLUMN) IN PANDAS (Part-2) - PYTHON PROGRAMMING


#SORTING DATAFRAME (BY COLUMN) IN PANDAS (Part-2) - PYTHON PROGRAMMING

Listing Two Rows


df[['Name','Total_Marks']]





df = df.drop(columns = "Total_Marks")
print(df)









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

MANIPULATING DATAFRAME IN PANDAS (ADD COLUMN , DROP COLUMN) || DATAFRAME MANIPULATIONS


import pandas as pd 
dt = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
df = pd.DataFrame(dt)
print(df)




df['Total_Marks'] = 0
print(df)




df['Total_Marks'] = df['Hindi']+df['English']
df







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

SORTING DATAFRAME (BY COLUMN) IN PANDAS - PYTHON PROGRAMMING

#SORTING DATAFRAME (BY COLUMN) IN PANDAS 


#clcoding

import pandas as pd

dt = pd.read_excel("FILE_NAME")

print(dt)

df = pd.DataFrame(dt)

df.sort_values("MAXMTEMPERATURE", ascending = False)










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

Monday 21 June 2021

How do you reverse the string without take another string?



#How do you reverse the string without take another string?
#clcoding
s = 'hello'
n = -1
for x in s:
    n += 1
while n >= 0:
    print(s[n], end = '')
    n -= 1








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

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);


}

Popular Posts

Categories

AI (31) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (20) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (886) Python Coding Challenge (284) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

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