Remove columns from tabular file user Kantale

From PyPedia
Jump to: navigation, search

Contents

[edit] Documentation

Removes columns from a tabular file. The columns_to_remove is a dictionary with the index of the columns to be removed.


[edit] Parameters

<inputs>
</inputs>


[edit] Return

None

[edit] See also

[edit] Code

def Remove_columns_from_tabular_file_user_Kantale(
	input_file = None, 
	columns_to_remove = None, 
	output_file = None, 
	sep = None,
	skip_first_lines = None,
	):

	input_f = open(input_file, 'U')
	output_f = open(output_file, 'w')

	line_n = 0
	while True:
		line = input_f.readline()
		if not line: break
		
		line_n += 1
		if line_n % 10000 == 0:
			print "Lines:", line_n, Print_now_user_Kantale()

		if skip_first_lines:
			if lines_n <= skip_first_lines:
				continue

		if sep:
			line_splitted = line.replace("\n", "").split(sep)
		else:
			line_splitted = line.replace("\n", "").split()
			
		line_to_write = [val for index, val in enumerate(line_splitted) if index not in columns_to_remove]
		output_f.write(str.join(sep, line_to_write) + "\n")

	output_f.close()
	input_f.close()

[edit] Unit Tests

def uni1():
	return True

[edit] Development Code

def Remove_columns_from_tabular_file_user_Kantale(input_file=None, columns_to_remove = None, output_file=None, sep="\t"):
	input_f = open(input_file, 'U')
	output_f = open(output_file, 'w')

[edit] Permissions

[edit] Documentation Permissions

Kantale

[edit] Code Permissions

Kantale

[edit] Unit Tests Permissions

Kantale

[edit] Permissions Permissions

Kantale

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox