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
  SyntaxError: unexpected character after line continuation character siteshkumar 2 309 Jul-13-2020, 07:05 PM
Last Post: snippsat
  Help ANSI character and python... sid4g 2 403 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 547 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  python cache for small integer Uchikago 1 767 Jun-27-2019, 05:32 PM
Last Post: ichabod801
  Error when entering letter/character instead of number/integer helplessnoobb 2 760 Jun-22-2019, 07:15 AM
Last Post: ThomasL
  Replace changing string including uppercase character with lowercase character silfer 11 1,681 Mar-25-2019, 12:54 PM
Last Post: silfer
  how to add a coma in print statement of python without preceding space character? brittocj 3 906 Sep-27-2018, 09:03 PM
Last Post: nilamo
  Python function that uses a word as the encryption key, rather than an integer wak_stephanie 4 1,729 Aug-31-2018, 12:16 PM
Last Post: perfringo
  How to sum up the elements of an integer using python split/join? mohanraj1986 5 1,104 Aug-27-2018, 09:13 AM
Last Post: perfringo
  How to convert character to integer in python rajeev1729 2 1,740 Oct-03-2017, 04:30 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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