Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:29+00:00 2026-06-11T11:14:29+00:00

I have a CSV file like that: ,LESCHELLES,,LESCHELLES ,SAINTE CROIX DE VERDON,,SAINTE CROIX DE

  • 0

I have a CSV file like that:

"","LESCHELLES","","LESCHELLES"
"","SAINTE CROIX DE VERDON","","SAINTE CROIX DE VERDON"
"","SERRE CHEVALIER","","SERRE CHEVALIER"
"","SAINT JUST D'ARDECHE","","SAINT JUST D'ARDECHE"
"","NEUVILLE SUR VANNES","","NEUVILLE SUR VANNES"
"","ESCUEILLENS ET SAINT JUST","","ESCUEILLENS ET SAINT JUST"
"","PAS DES LANCIERS","","PAS DES LANCIERS"
"","PLAN DE CAMPAGNE","","PLAN DE CAMPAGNE"

And I’d like to convert it this way:

"","Leschelles","","LESCHELLES"
"","Sainte Croix De Verdon","","SAINTE CROIX DE VERDON","STE CROIX DE VERDON","93"
"","Serre Chevalier","","SERRE CHEVALIER","SERRE CHEVALIER","93"
"","Saint Just D'Ardeche","","SAINT JUST D'ARDECHE"
"","Neuville Sur Vannes","","NEUVILLE SUR VANNES"
"","Escueillens Et Saint Just","","ESCUEILLENS ET SAINT JUST","ESCUEILLENS ET ST JUST","91"
"","Luc","","LUC"
"","Pas Des Lanciers","","PAS DES LANCIERS","PAS DES LANCIERS","93"
"","Plan De Campagne","","PLAN DE CAMPAGNE","PLAN DE CAMPAGNE","93"

This would be nice. And better: lowercase all “whole” words like de, d', et, sur and des. This would give:

"","Leschelles","","LESCHELLES"
"","Sainte Croix de Verdon","","SAINTE CROIX DE VERDON","STE CROIX DE VERDON","93"
"","Serre Chevalier","","SERRE CHEVALIER","SERRE CHEVALIER","93"
"","Saint Just d'Ardeche","","SAINT JUST D'ARDECHE"
"","Neuville sur Vannes","","NEUVILLE SUR VANNES"
"","Escueillens et Saint Just","","ESCUEILLENS ET SAINT JUST","ESCUEILLENS ET ST JUST","91"
"","Luc","","LUC"
"","Pas des Lanciers","","PAS DES LANCIERS","PAS DES LANCIERS","93"
"","Plan de Campagne","","PLAN DE CAMPAGNE","PLAN DE CAMPAGNE","93"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:14:31+00:00Added an answer on June 11, 2026 at 11:14 am

    Python has title():

    Return a titlecased version of the string where words start with an
    uppercase character and the remaining characters are lowercase.

    The algorithm uses a simple language-independent definition of a word
    as groups of consecutive letters. The definition works in many
    contexts but it means that apostrophes in contractions and possessives
    form word boundaries, which may not be the desired result:

    "they're bill's friends from the UK".title() "They'Re Bill'S Friends From The Uk"
    

    A workaround for apostrophes can be constructed
    using regular expressions:

     import re
     def titlecase(s):
         return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
                       lambda mo: mo.group(0)[0].upper() +
                                  mo.group(0)[1:].lower(),
                       s)
    
     titlecase("they're bill's friends.") "They're Bill's Friends."
    

    Update: here’s the solution for French problem:

    import re, sys 
    
    def titlecase(s):
        return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
            lambda mo: mo.group(0)[0].upper() +
                       mo.group(0)[1:].lower(),
            s)  
    
    def french_parse(s):
        p = re.compile(
            r"( de la | sur | sous | la | de | les | du | le | au | aux | en | des | et )|(( d'| l')([a-z]+))",
            re.IGNORECASE)
        return p.sub(
            lambda mo: mo.group().find("'")>0
                       and mo.group()[:mo.group().find("'")+1].lower() +
                           titlecase(mo.group()[mo.group().find("'")+1:])
                       or (mo.group(0)[0].upper() + mo.group(0)[1:].lower()),
            s); 
    
    for line in sys.stdin:
        s = line[20:len(line)-1]
        p = s.find('"')
        t = s[:p]
        # Just output to show which names have been modified:
        if french_parse( titlecase(t) ) != titlecase(t):
            print '"' + french_parse( titlecase(t) ) + '"'
    

    Just launch it like this:

    python thepythonscript.py < file.csv
    

    Then the output will be:

    "Grenand les Sombernon"
    "Touville sur Montfort"
    "Fontenay en Vexin"
    "Durfort Saint Martin de Sossenac"
    "Monclar d'Armagnac"
    "Ports sur Vienne"
    "Saint Barthelemy de Beaurepaire"
    "Saint Bernard du Touvet"
    "Rosoy le Vieil"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file that goes something like this: ['Name1', '', '', '',
I have a CSV file that is formatted like: 0.0023709,8.5752e-007,4.847e-008 and I would like
I have a file that can be any thing like ZIP, RAR, txt, CSV,
I have a CSV file formatted just like this: name,color,tasty,qty apple,red,true,3 orange,orange,false,4 pear,greenish-yellowish,true,1 As
So I have a CSV file that looks like this: 12345, Here is some
I have a csv file that has like 30,000 rows in it. It also
I have a CSV-like text file that has about 1000 lines. Between each record
I have a CSV file that has data like this 15,I,2,41301888,BYRNESS RAW,,BYRNESS VILLAGE,NORTHUMBERLAND,ENG 11,I,3,41350101,2,2935,2,2008-01-09,1,8,0,2003-02-01,,2009-12-22,2003-02-11,377016.00,601912.00,377105.00,602354.00,10
I have a csv file that looks something like this (actual file has many
I have a csv file that looks like this NumberofNullAsOfDates 0 I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.