Search code examples
pythoncsvlowercase

CSV Content in lowercase before processing?


Hey everyone :) I'm struggling because I have a big CSV-File where in one column the data should be considered case-insensitive, how can I fix that Python considers all rows of that column as lower (anton = ANTon)? That's what I tried:

def CSV_firstnameshouldbelowered(csv_data):
    csv_record[First_Name] = csv_record[First_Name].lower()

    firstnameislowernow = {
    First_Name: csv_record[First_Name],
    Age: csv_record[Age]
}

return firstnameislowernow

Sadly I can't use .lower() here because it's not a string. How can I change that columns content into lowercase? The part "firstnameislowernow" should be modified with the implementation before, otherwise I can't further process the data with my code :)


Solution

  • Convert to string first, then use lower()

    firstNameStr = str(csv_record[First_Name]) 
    firstNameStr = firstNameStr.lower()