Python Forum
How to map character to integer in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to map character to integer in python
#1
suppose we have one csv file containing 2*2 matrix like
Name Age Problem
Rajeev 30 Y
Kumar 32 N
Madan 31 Y
I want to convert Y to 1 and N to 0 into csv file by using python.
Reply
#2
1. Open the file for reading, open output file for writing
2. Read the each line and parse it, replacing Y/N values
3. Write the new line in the output file

this can be done with basic file operations or you can use csv module
also tutorial on working with files
https://python-forum.io/Thread-Basic-Files

and by the way this is not 2x2 matrix
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python escaping character atom509 1 126 May-29-2024, 08:57 PM
Last Post: DeaD_EyE
  Python rule about the space character surrounding the equal sign ineuw 10 1,846 Sep-21-2023, 09:17 AM
Last Post: ineuw
  How do I handle escape character in parameter arguments in Python? JKR 6 1,402 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  [solved] unexpected character after line continuation character paul18fr 4 3,607 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  python error: bad character range \|-t at position 12 faustineaiden 0 3,775 May-28-2021, 09:38 AM
Last Post: faustineaiden
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,609 May-24-2021, 08:48 AM
Last Post: bowlofred
  Reducing JSON character count in Python for a Twitter Bot johnmitchell85 2 65,233 Apr-28-2021, 06:08 PM
Last Post: johnmitchell85
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,281 Jul-13-2020, 07:05 PM
Last Post: snippsat
  Help ANSI character and python... sid4g 2 2,499 Mar-19-2020, 06:08 PM
Last Post: sid4g
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,823 Jan-05-2020, 11:50 AM
Last Post: vivekagrey

Forum Jump:

User Panel Messages

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