简体   繁体   中英

How do I remove all the letters from a CSV file?

How would I go about removing letters and numbers except 1s and 0s from my CSV file. I have tried using Pandas but I do not think that I used it correctly to accomplish the task.

Assuming you have already loaded this file into a matrix (stored in variable csv here):

for x in range(len(csv)):
    for y in range(len(csv[x])):
        if csv[x][y] not in ["1", "0"]:
            csv[x][y] = ""

This code will change all characters, that are not 1s or 0s to empty strings. If necessary, you can easily modify this code to change them to any other value, or completely remove them from the matrix (however, in this case, while loops are necessary).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM