Python Forum
How to map character to integer in python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: How to map character to integer in python (/Thread-How-to-map-character-to-integer-in-python)



How to map character to integer in python - rajeev1729 - Oct-02-2017

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.


RE: How to map character to integer in python - buran - Oct-02-2017

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