print coulmn name in saved csv file using python

Question:

I want to know that how much null values exist in every column of my data. As my data is too large I am saving the result in csv to get a clear picture. But the problem is in my csv, I am unable to see the column name. What should i do to to print the column name against the sum of null values in my CSV file?

  aw= data.isnull().sum()
  aw.to_csv (r'C:/Users/a.csv', index = False, header=True)

my CSV file looks like this
0
0
0
10
0
9

I want to see it like this

feature1 0 feature2 0 feature3 0 feature4 11
feature5 12 feature6 12

Asked By: user12

||

Answers:

the resulting aw is not a DataFrame. To check type(aw) output pandas.core.series.Series

what you could try is

aw = pd.DataFrame(data.isnull().sum()).T

the output is

    feature1    feature2    feature3
0   0           0           0
Answered By: perpetualstudent

try this

import pandas as pd

data = pd.read_csv('a.csv', sep=' ', header=None)
data.columns = ['feature1', 'feature2', 'feature3', 'feature4', 'feature5', 'feature6']
print(data)

   feature1  feature2  feature3  feature4  feature5  feature6
0         0         0         0        10         0         9
Answered By: Gold79
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.