Codied To Clipboard !
Home > Notes > Python Pandas
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
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.
df1 = pd.read_csv('/content/first_test.csv') df1.drop(['id', 'area'],1,inplace=True) print(df1) #pd.concat([df1,df2])
The sort_values() method sorts the DataFrame by the specified label.
#res1 = df1.sort_values(by=['zip'], ascending=True) res2 = df1.sort_values(by=['zip'], ascending=False) print(res2)
using rename we can rename From Source to column name.
df1.rename(columns = {'id':'id1', 'area':'area2'}, inplace = True) df1