-1

I am extremely new to python and want to learn how to pull certain elements from a data sheet. For example:

  1. How many attributes/categories the data has?
  2. How many missing values the data has?
  3. How many columns the data has?
  4. The frequency of an element in a single column

I have gotten as far as printing the data but am wondering how I can compute the above values via while loops or for loops

file=open('9car.csv','r')

M=[]
lines=file.readlines()
for row in lines:
     value=row.strip()
     items=value.split()
     # print(items)
     print(value)
     # print(values)

for row in M:
     count=len(row)
     print(count)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • Please stick to a single question. That being said, this site is terrible resource for learning how to code. You are best served by reading books or doing online tutorials and coming here with specific questions related to specific code you are having trouble with. –  Nov 15 '17 at 02:08

2 Answers2

0

For answering questions like these, pandas would be a better and convenient option.

import pandas as pd
df = pd.read_csv('9car.csv')
1. df['col_name'].unique()
2. pd.isnull(df['col_name']).sum()
3. len(df.columns)
4. df['col_name'].value_count()
theSanjeev
  • 149
  • 2
  • 10
0

The standard library (documented for your version of python at python.org) contains a module called csv. It has a number of functions for parsing csv files. This may be a better solution for you than trying to read and parse each line from scratch.

Todd Carney
  • 165
  • 13