I am new to python development and and I am trying to separate csv file into two different text files based on null values
my csv file has data like
and
My csv file contains four fields facility, Truck, Driver and licences truck and driver has some of the null values I want to create two separate files for row values where truck value us null and another file will contain information where driver value is null.
I tried the following code but it is not eliminating null values it shows either 0 or space in text file
License = pd.read_csv("E:\ActiveCityLicenses.csv")
a=License.isnull().sum()
print(a)
print(License.shape)
m=License[License['TRUCK_ID'].isnull()]
print(m)
n=License.dropna(axis= 0, subset= ['TRUCK_ID'], inplace=True)
print(n)
License.to_csv(r'E:\DriverLicense.txt', header=None, index=None, mode='w', columns=None)
#I had to create two data frames as after doing first dorpna entire frame gets empty
License1 = pd.read_csv("E:\ActiveCityLicenses.csv")
p=License1.dropna(axis= 0, subset= ['EMPLOYEE_ID'], inplace=True)
print(p)
License1.to_csv(r'E:\TruckLicense.txt', header=None, index=None, sep=',', mode='w')
Can anyone please suggest a better approach of doing it, or what I am missing over here? output in the text file is
A119,BF01,,TOR|MARK|BRAM|MISS|RHILL|VAU
A119,BF03,,TOR|MARK|BRAM|MISS|RHILL|VAU
A119,BF04,,TOR|MARK|BRAM|MISS|RHILL|VAU
A119,BF05,,TOR|MARK|BRAM|MISS|RHILL|VAU
space should not be there.
df= df[pd.notnull(df['TRUCK_ID'])]