Dec-13-2018, 06:49 AM
Hi, I have difficulty doing my loop, will appreciate any help.
my isnumeric() is not working, i just need to show that isnumeric is false.
My loop is to count the total number of unique values in every column in a csv file.
Thanks.
my isnumeric() is not working, i just need to show that isnumeric is false.
My loop is to count the total number of unique values in every column in a csv file.
Thanks.
import numpy as np ### Read the hdb resale price index csv file with the loadtxt() function hdbrpi = "CA1data/housing-and-development-board-resale-price-index-1q2009-100-quarterly.csv" data = np.genfromtxt(hdbrpi, delimiter=",", skip_header=1, dtype=[('quarter', 'U50'), ('index', 'U50')]) ### Print out total rows and columns of data in the file print("***HDB Resale Price Index***") print() print(f"There are {len(data)} rows and {len(data[0])} columns of data in this dataset {hdbrpi}") print() ### Print out the names of the columns in the file print("The names of the columns are:") with open(hdbrpi) as data: data = np.genfromtxt(hdbrpi, delimiter=",", skip_header=1, dtype=[('quarter', 'U50'), ('index', 'U50')]) line_count = 0 for line_count in data: if line_count >= 0: print(row[line_count], type(row[line_count]) , "isnumeric:", row[line_count].isnumeric()) #unique_elements, counts_elements = np.unique(data, return_counts=True) #print(unique_elements, counts_elements) #print(np.unique(row[line_count], return_counts = true)) line_count += 1 print(line_count)