Skip to main content

1. Write a Python program to create a dataframe containing columns name, age and percentage. Add 10 rows to the dataframe. View the dataframe. 2. Write a Python program to print the shape, number of rows-columns, data types, feature names and the description of the data 3. Write a Python program to view basic statistical details of the data. 4. Write a Python program to Add 5 rows with duplicate values and missing values. Add a column ‘remarks’ with empty values. Display the data 5. Write a Python program to get the number of observations, missing values and duplicate values. 6. Write a Python program to drop ‘remarks’ column from the dataframe. Also drop all null and empty values. Print the modified data.

import pandas as pd
import matplotlib.pyplot as plt
#import seaborn as sns
 
df=pd.DataFrame(columns=['name','age','percentage'])
df.loc[0]=['lina',19,93]
df.loc[1]=['shruti',18,89]
df.loc[2]=['sakshi',17,90]
df.loc[3]=['pallavi',18,87]
df.loc[4]=['arpita',19,92]
df.loc[5]=['sneha',18,89]
df.loc[6]=['siddhi',20,88]
df.loc[7]=['sejal',20,87]
df.loc[8]=['prachi',19,85]
df.loc[9]=['nikita',20,89]
print(df)

print("Shape of data:",df.shape)
print("No.of rows & columns:",df.size)
print("Data types:",df.dtypes)
print("Features names:",df.info())
print("Description of data:",df.describe())

df.loc[10]=['lina',19,93]
df.loc[11]=['shruti',18,89]
df.loc[12]=['yogita',17,None]
df.loc[13]=['sangeeta',None,87]
df.loc[14]=['ankita',19,92]
df['remark']=None
print(df)

print("Number of obeservation:",df.info())
print("Missing values:",df.isnull())
print("Dupalicate values:",df.duplicated())

df.drop(columns='remark',axis=1,inplace=True)
print(df)
#df.fillna()
#df.dropna()
print(df)

print(df.plot(x='name', y='percentage'))
plt.show()

#print(df.plot.scatter(x="name",y="percentage"))
#plt.show()

Comments

Popular posts from this blog

Write a program to read book information (bookid, bookname, bookprice, bookqty) in file “book.dat”. Write a menu driven program to perform the following operations using Random access file: i. Search for a specific book by name. ii. Display all book and total cost

  import java . io .*; import java . util .*; class Book {       String name , id ;       int qty ;       double price , total ;       Book ( String i , String n , String p , String q )      {               name = n ;               id = i ;               qty = Integer . parseInt ( q );               price = Double . parseDouble ( p );               total = qty * price ;      }       public String toString ()      {               System . out . println ( "name\t id\t qty\t price\t total" );               String s = name + "\t" + id + "\t" + qty + "\t" + price + "\t" + total ;           ...

Define a class MyDate (day, month, year) with methods to accept and display a MyDate object. Accept date as dd, mm, yyyy. Throw user defined exception “InvalidDateException” if the date is invalid. Examples of invalid dates : 03 15 2019, 31 6 2000, 29 2 2021

  import java . io .*; import java . util .*; class InvalidDateException extends Exception {       InvalidDateException ()       {               System . out . println ( "Invalid Date" );       } } class MyDate {       int day , mon , yr ;       void accept ( int d , int m , int y )       {             day = d ;             mon = m ;             yr = y ;       }       void display ()       {             System . out . println ( "Date is valid : " + day + "/" + mon + "/" + yr );       } } class Date {       public static void main ( String args []) throws Exception       {             Scanner sc = new Sca...

Write a Java program to design a screen using Awt that will take a user name and password. If the user name and password are not same, raise an Exception with appropriate message. User can have 3 login chances only. Use clear button to clear the TextFields.

  import java . awt .*; import java . awt . event .*; import javax . swing .*; class InvalidPasswordException extends Exception {       InvalidPasswordException ()       {             System . out . println ( "Username and password is not same" );       } } public class Password extends Frame implements ActionListener {       Label uname , upass ;       TextField nametext ;       TextField passtext , msg ;       Button login , Clear ;       Panel p ;       int attempt = 0 ;       char c = '*' ;             public void login ()       {             p = new Panel ();             uname = new Label ( "Username : " , Label . CENTER );             upass = n...