Difference makes the DIFFERENCE
import pandas as pd
df = pd.read_csv('/content/clean_agri_ds.csv')
df.head(1)
reqd_list = ['Season', 'District_Name', 'Area', 'Production', 'Crop_Year' ]
input_list = []
input_list = df.columns
input_list
reqd_list[2]
hasCols = []
for item in reqd_list:
if item in input_list:
print(" order =>", item)
hasCols.append(item)
else:
print("not in order =>", item)
# df.drop[item, inplace = True]
print (hasCols)
hasCols
ndf = df[['Season', 'Crop', 'State_Name', 'Crop_Year']]
ndf.head(2)
new = df.filter(hasCols, axis=1)
new.head(2)
all(i == j for i, j in zip(reqd_list, input_list))
Clean Agriculture Dataset used in code