pandas Operations part1

Estimated reading: 2 minutes 319 views

Below ate the pandas opertaion 1 Example.

				
					import numpy as np
import pandas as pd
df = pd.read_csv('/content/first_test.csv')
#print(df)
#df.info()
#print(df[["id","name"]])
#print(df.groupby(by=["zip"]).size())
#print(df["id"].sum())
#print(df["id"].count())
#print(df["id"].max())
#print(df["id"].min())
#df["id"].mean()
#df.groupby('zip')['id'].sum()
#print(df[df.id==1])
#print(df[(df.id == 1) & (df.zip == 560098)])
#print(df[(df.id == 1) | (df.zip == 560098)])
'''for index, row in df.iterrows():
    print(row["id"],",",row["name"])'''

#arr = df["zip"].unique()   
#print(arr)    
#df.head()
df.describe()
				
			

Below ate the pandas opertaion 1 Example.

				
					import numpy as np
import pandas as pd
df = pd.read_csv('/content/first_test.csv')
from pandasql import sqldf

output = sqldf("select * from df")
output

				
			

drop

The drop() method removes the specified row or column.

By specifying the column axis (axis='columns'), the drop() method removes the specified column.

By specifying the row axis (axis='index'), the drop() method removes the specified row.


Syntax

dataframe.drop(labels, axis, index, columns, level, inplace., errors)
				
					df1 = pd.read_csv('/content/first_test.csv')
df1.drop(['id', 'area'],1,inplace=True)
print(df1)
#pd.concat([df1,df2])
				
			

sort_values()

The sort_values() method sorts the DataFrame by the specified label.


Syntax

dataframe.sort_values(by, axis, ascending, inplace, kind, na_position, ignore_index, key)
				
					#res1 = df1.sort_values(by=['zip'], ascending=True)
res2 = df1.sort_values(by=['zip'], ascending=False)
print(res2)
				
			

rename

using rename we can rename From Source to column name.

				
					df1.rename(columns = {'id':'id1', 'area':'area2'}, inplace = True)
df1
				
			

Add Your Heading Text Here

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

				
					console.log( 'Code is Poetry' );
				
			

Leave a Comment

CONTENTS