You are on page 1of 3

# How to remove a column from Data Frame

del DF["CLASS"] # It will delete/remove "CLASS" column from Data Frame


DF
____
# How to remove a row from DataFrame
DF = DF.drop(3) # It will delete/drop/remove a row has id - 3 from Data Frame
DF

# Adding a new Row in DataFrame


DF.at[4,:] = [104,"HARSHIT","12C"]
print(DF)
_____
D = {"ROLLNO":103,"NAME":"PRAKHAR","CLASS":"12D"} # Create a Dictionary for new row
DF = DF.append(D , ignore_index=True)
DF

# Change the value of a Column in a record/row


DF.at[1:1,2:3] = "12E"
DF

# DataFrame
import pandas as pd
S1 = [100,"AYUSH","12D"]
S2 = [101,"PALASH","12A"]
S3 = [102,"VISHAL","12C"]
DF = pd.DataFrame([S1,S2,S3],columns=["ROLLNO","NAME","CLASS"])
#print(DF) # Show Full Data Frame
print(DF.iloc[1:2,1:2]) # iloc - Index Location of a Record in Data Frame

# use of head()/tail() functions


import pandas as pd
S = pd.Series(data=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
print("Show Data from Head/Top")
print(S.head(2))
print("Bottom Data")
print(S.tail(3))

# Sort Data of Series


import pandas as pd
S = pd.Series(data=[11,25,2,7,1])
# Sorting Data of Series
S = S.sort_values(ascending=True)
print(S)

# Revision of DataFrame
import pandas as pd
R1 = {"ROLLNO":12401,"NAME":"ALFIYA"} # Rows creates with Dictionary
R2 = {"ROLLNO":12402,"NAME":"AYUSH"}
R3 = {"ROLLNO":12403,"NAME":"RAM"}
DF = pd.DataFrame([R1,R2,R3]) # DataFrame creates with list of Dictionaries
DF
______
import pandas as pd
R1 = {"TID":"T1","TNAME":"S K UPADHAYAY","POST":"PGT","SUB":"COMP. SC."}
R2 = {"TID":"T2","TNAME":"P PIPLODIA","POST":"PGT","SUB":"ACCOUNTANCY"}
R3 = {"TID":"T3","TNAME":"Y K TIRKEY","POST":"PGT","SUB":"ENGLISH"}
TEACHER = pd.DataFrame([R1,R2,R3])
TEACHER

You might also like