This document introduces the pandas library in Python, which is used for data analysis and manipulation. It demonstrates how to import pandas, read in a CSV file, and explore different functions for viewing, selecting, and cleaning the data frame. Various methods are shown for accessing, indexing, sorting, and modifying the data within the pandas data frame.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
57 views
Introduction To Pandas Library
This document introduces the pandas library in Python, which is used for data analysis and manipulation. It demonstrates how to import pandas, read in a CSV file, and explore different functions for viewing, selecting, and cleaning the data frame. Various methods are shown for accessing, indexing, sorting, and modifying the data within the pandas data frame.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
Introduction to PANDAS Library
# this the method of importing pandas library
import pandas as pd #pd is convention # lets work with data frame. Data frame in pandas is nothing but set of data """ mainly we use pandas for data analysis. so it is full of readning and witing and manuplating of the data. """ # read_csv is the method for reading the data in the csv file # explanation about csv file rd=pd.read_csv (r"C:\Users\Asus\AppData\Local\Programs\Python\Python38- 32\par.csv" ) print(rd) print("================") print(rd.head(2))# head() is teh function which takes only one parameter and returns that many lines of data """ lets try head() function eith negitive parameter""" print("*****") print(rd.head(-2)) """ lets work with tail() function""" #tail() is the function which takes only one parameter and returns that many data from last print("----------------------") print(rd.tail(2)) # lets try the tail function with negitive paramerter print(":::::::::::::::::::::::") print(rd.tail(-2)) print("++++++++++") print(type(rd))#type function returns the type of the data #lets how to access a single row of the dataframe print(rd['name'])#hare we are accessing only the name coloumn of the data frame print(type(rd['name']))# lets know the datya type of single coloum """ discuss about the nan values that is when one the value in the csv fileis not her that value is repalced by nan in python""" print("^^^^^^^^^^^^^^^^^^^^^^") print(rd.dtypes)# pandas series are one dimmensional labeled array capable of holding data of any type print("++++++++++++++++++++++++++") print(rd.shape)#shape fun prints the rows and columns print(":::::::::::::::::::::::::::::") print(rd.size)#size fun returns the no elements in the data frame print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") print(len(rd))# len function returns the no of rows print(rd.info()) print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %") """ lets work eith indexing of data framess in pandas""" print(rd.columns) print(rd.values)#prints values of the dataframe nn=rd['name']# assigns name column to nn print(nn) print("NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNNN") print(rd.loc[1])#here we are accessing only ist coloumn print(nn.values)# prints nn values gh=pd.read_csv (r"C:\Users\Asus\AppData\Local\Programs\Python\Python38- 32\par.csv",index_col='name') """ in the above line we are ,making the index column as name column""" print(gh) k=rd['name'].values# here we are assinging the values of name column to k print(k) """ lets how to clean the data""" print("::::::::::::::::::::") ni=pd.read_csv (r"C:\Users\Asus\AppData\Local\Programs\Python\Python38- 32\par.csv" ) print(ni) nit=ni.drop(['no'],axis=1)#here we are deleting the n row print("<><><><><><><><><><><><><><><><><><><>") print(nit) bit=ni.drop([2,3],axis=0)#here we are deleting 2 and 3 colums print("//////////////////////////////////////") print(bit) """ lets learn how to rename the dataframe columns""" col=['names','num','depart'] ni.columns=col print("#####################################") print(ni) """ lets manuplate the data in the data frame simply manuplation of data""" mn=ni.sort_values(by='num',ascending=True)# here we are arranging the data in the ascending order print("*******") print(mn) print("::::::::::::::::::::::::::::") bb=rd[rd.no<110]# here we are printing the no colunm values less than 110 print(bb) print("******") """ lets know about loc function""" print(rd.iloc[: :])# here we are accessing only some set of data from dataframe print("###############################@@@@@@@@@@@@@@@ @@@@") """lets work with correction of data""" nithin=rd['name'].str.upper()#here we are making the data of names coloumn into upper case print(nithin)