Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104859

Different sources of file

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Val Krem <valkrem@yahoo.com>
Newsgroups comp.lang.python
Subject Different sources of file
Date Mon, 14 Mar 2016 20:56:44 +0000 (UTC)
Lines 66
Message-ID <mailman.128.1457989225.12893.python-list@python.org> (permalink)
References <391627201.251709.1457795607818.JavaMail.yahoo.ref@mail.yahoo.com> <391627201.251709.1457795607818.JavaMail.yahoo@mail.yahoo.com>
Reply-To Val Krem <valkrem@yahoo.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de tDZnzZGyxcDr3iyEPm/aMQ9QB3Yt1XYbnMj3gTOdOcaA==
Return-Path <valkrem@yahoo.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'sys': 0.05; 'column': 0.07; 'subject:file': 0.07; 'collections': 0.09; 'csv': 0.09; 'python.': 0.11; 'output': 0.13; '"m"': 0.16; '(x1,': 0.16; 'columns': 0.16; 'concatenate': 0.16; 'count)': 0.16; 'f1:': 0.16; 'received:72.30.238': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Different': 0.16; 'variable': 0.18; 'all,': 0.20; 'to:name:python-list@python.org': 0.20; 'file.': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'skip:# 10': 0.27; 'finally,': 0.27; 'skip:( 20': 0.28; 'record': 0.29; 'recorded': 0.29; 'character': 0.29; 'file': 0.34; 'attempt': 0.35; 'but': 0.36; 'there': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'say': 0.37; 'sources': 0.37; 'doing': 0.38; 'progress': 0.38; 'received:66': 0.38; 'delete': 0.38; 'files': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'total': 0.62; 'different': 0.63; 'great': 0.63; 'received:98.139.212': 0.66; 'header:Reply-To:1': 0.67; 'records': 0.70; 'received:bullet.mail.bf1.yahoo.com': 0.72; 'message- id:@mail.yahoo.com': 0.84; 'male': 0.93; 'sex': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1457989017; bh=wjn6V+6qZ0lIlPFLIwkcwKxyCZBqVh1lzNBvC9anwCk=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=QJlx74hbuHlM9IgXQYD5aoukfer2IbCVrOYdxlHD+9SUEX+Z6boE8jnwHWJmGEn8Pev2xZCVch9U5t40gqBtC1tygH4ozeAfjho1xtZwpZODg+lp79M0N2J7+menJXgZDy2m5cgL+m31tdSw84HREh77UJRAaf8dy95BkA5A7afgPS1NZv25JoaUPBaD5vWkVCa9qoJ7LgAySi3bfWpUf+nUqPWnDpc7cnwXcQx3Efu59cA+JUEM+ljxc/8TkLGmNU3WTrhiqAi2EctVWVYaxYWIuyoVU06LYSphekbMSVLJM9Ms58VwdF3rA/zH95ISW/NkZPaoxRm0BFJnLS68+w==
X-Yahoo-Newman-Property ymail-3
X-Yahoo-Newman-Id 411094.90272.bm@omp1023.mail.bf1.yahoo.com
X-YMail-OSG 3fCtKOkVM1lBp0qKn4eL9bxxATdr.EiAXHLAoNbl2kdC2GxyiGohrzqQI5uL62e nZq6jFUed4BQ0FSYGk6c33BxMNfDCypYZ4M7OWqLIMwmXg5f7HXviEkDejAfu.T4zujRKXVQAVtF GXMr.kCur9yt3gAOX_IwBgXJmULVI8K6X6RjyNBvTzHl8OBN8WV0A068akdQsz_Qr_jq50lxsDNQ _fFyfFOU.wtAykitE7NrsVq97xNDTcu8lDhIv0Mdrj5DEa2_JPmgtHe5ow7yQuQxplgdoHFk50ou .DIKyfuvUH0h9wVX0gKO7gN9pO3A5GnA3TSuaPgMGETwWsw0XoWAJqCZQuIKkqmMxe3dCOfgaENQ qdkZ7.vAXa8.bk5hijZYwkqWzj7woV.KL_dQOnRdT_27AP_ni1vAvfLOunolu4tP_bY_9maCsXEU QBDQAvUxgNQZxrtD4YVdIXAGJHvuMZCivzPr7.2Gxz9v8dtxczkxXBAluprvSv7.n4Q7ppvdn3kT bvpUo
In-Reply-To <391627201.251709.1457795607818.JavaMail.yahoo@mail.yahoo.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:104859

Show key headers only | View raw



Hi all,



I am made a little progress on using python.
I have five files to read from different sources  and concatenate them to one file.  From each file I want only to pick  few column  (x1, x2  and  x3). However, these columns say x3 was  a date in one file it was recorded as a character  (2015/12/26)  and in the other file it was records  (20151226)  and in the other file it was recorded as  (26122015). How do I standardized these into one form (yyyymmdd-20151126). If there is no date then delete that record

2. The other variable x2. In one of the one files it was recorded as  "M" and "F". In the other  file  x3  is  1 for male and 2 for female.  So I want to change  all to 1 or 2. if this variable is out of range M / F or 1 or 2 then delete that record

3.  After doing all these I want combine all files into one  and send it to output. 

Finally, do some statistics  such as number of records read from each file. Distribution of sex  and total number of records sent out to a file.

Below is my attempt but not great
#!/usr/bin/python
import sys
import csv
from collections import Counter

N=10
count=0
with open("file1") as f1:
for line in f1:
count+=1
print("Total Number of records read", count)
# I want to see the first few lines of the data


file1Name   x2    x3
Alex1  F   2015/02/11
Alex2  M   2012/01/27
Alex3  F   2011/10/20
Alex4  M   .
Alex5  N   2003/11/14

file2
Name  x2    x3
Bob1  1   2010-02-10
Bob2  2   2001-01-07
Bob3  1   2002-10-21
Bob4  2   2004-11-17
bob5  0   2009-11-19

file2
Name    x2    x3
Alexa1  0   12102013
Alexa2  2   20012007
Alexa3  1   11052002
Alexa4  2   26112004
Alexa5  2   15072009

Output to a file 
Name x2  x3
Alex1   2   20150211
Alex2   1   20120127
Alex3   2   20111020
Bob1    1   20100210
Bob2    2   20010107
Bob3    1   20021021
Bob4    2   20041117
Alexa2  2   20070120
Alexa3  1   20020511
Alexa4  2   20041126
Alexa5  2   20090715

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Different sources of file Val Krem <valkrem@yahoo.com> - 2016-03-14 20:56 +0000

csiph-web