Python Forum
Creating csv file from another file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating csv file from another file
#1
I have a file that is exported from an upstream system and data is not the same in each row.

But the main attributes in the file are below. Not all the rows might have all the attributes.

unitnumber
idnumber
mail
givenname
manager
department
city
title
mobile

Contents in the file are as below and can only have the above attributes.

i/p:
Quote:('uid=test.test51,ou=People,o=ic.com,o=xerox', {'city': ['Irving'], 'title': ['Application Developer'], 'mobile': ['2054444444'], 'manager': ['test.test100'], 'idnumber': ['44451'], 'department': ['National Claims'], 'mail': ['test.test51@infinityplus.com'], 'givenname': ['Test1'], 'unitnumber': ['551']})
('uid=pinuser,ou=People,o=ic.com,o=xerox', {'givenname': ['Pin']})
('uid=jim.gober,ou=People,o=ic.com,o=xerox', {'city': ['Birmingham'], 'title': ['CEO'], 'manager': ['jim.gober'], 'idnumber': ['137741'], 'department': ['Executive'], 'givenname': ['James'], 'unitnumber': ['887']})
('uid=ServiceAdmin,ou=People,o=ic.com,o=xerox', {})
('uid=joann.kerr,ou=People,o=ic.com,o=xerox', {'city': ['Alpharetta'], 'title': ['Senior Software Architect'], 'manager': ['Cynthia Berger'], 'idnumber': ['0003677'], 'department': ['Information Technology'], 'givenname': ['Joann'], 'unitnumber': ['SHD']})

I need to create a csv file from this that has the data in the below format


required o/p:

1st line with header that can be static followed by the data from the above file.
Quote:unitnumber,idnumber,mail,givenname,manager,department,city,title,mobile
551,44451,test.test51@infinityplus.com,Test1,test.test100,National Claims,Irving,Application Developer,2054444444
,,,Pin,,,,,
887,137741,,James,jim.gober,Executive,Birmingham,CEO,
,,,,,,,,
SHD,0003677,,Joann,Cynthia Berger,Information Technology,Alpharetta,Senior Software Architect,

Any help is appreciated
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there anyway to make a .py file into a .exe file? Oshadha 2 134 Jan-13-2021, 04:58 AM
Last Post: Oshadha
  [split] How to convert the CSV text file into a txt file Pinto94 5 166 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  xml file creation from an XML file template and data from an excel file naji_python 1 125 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  how to automate sending bulk emails from an excel file or a calc-file apollo 0 166 Dec-10-2020, 08:43 PM
Last Post: apollo
  how to change the range of read CSV file every time python file runs greenpine 6 239 Dec-08-2020, 10:11 PM
Last Post: greenpine
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 433 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Convert file of hex strings to binary file medatib531 4 437 Oct-09-2020, 05:42 PM
Last Post: DeaD_EyE
  saving data from text file to CSV file in python having delimiter as space K11 1 304 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Trouble with reading csv file and putting it into a file Milfredo 3 382 Sep-04-2020, 05:30 AM
Last Post: Milfredo
  What is meant by "truncates the file" RE file.open(w+b)? MysticLord 5 504 Sep-01-2020, 08:36 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020