0 Daumen
26 Aufrufe

Ich möchte den Header einiger Dateien umbenennen und die Spalten hinzufügen, die schließlich gruppiert werden sollen. Tatsächlich habe ich eine Datei mit Namen, Ergebnissen und zusätzlichen Metadaten und eine weitere, die zwischen den Namen der Dateien und den gewünschten Namen zugeordnet ist. Zum Beispiel ist hier ein Teil der :

    Map Level, Precinct ID, Precinct Name,#1 - Georgian Dream,#1 - Giorgi Margvelashvili,#1 - Mikheil Saakashvili,#1 - United National Movement,#10 - National Democratic Party of Georgia,#10 - Nino Chanishvili,#10 - Traditionalists - Our Georgia and Women's Party,#11 - Giorgi Liluashvili,#11 - National Party of Radical Democrats of Georgia,#11 - Sportsman's Union,#12 - Akaki Asatiani,#12 - Future Georgia,#12 - Our Country,#13 - Freedom Party,#13 - Teimuraz Mzhavia,#14 - Mamuka Melikishvili,#14 - Nugzar Avaliani,#14 - Public Movement,#15 - People's Party,#16 - Labour Council of Georgia,#16 - Mikheil Saluashvili,#17 - Giorgi Chikhladze,#18 - Nestan Kirtadze,#19 - Tamaz Bibiluri,#2 - Christian-Democratic Movement,#2 - Davit Bakradze,#2 - Levan Gachechiladze,#2 - Republican party,#2 - United National Movement,#2 - United Opposition,#20 - Avtandil Margiani,#21 - Kartlos Gharibashvili,#22 - Teimuraz Bobokhidze,#23 - Mamuka Chokhonelidze,#3 - Arkadi (Badri) Patarkatsishvili,#3 - Christian-Democratic Movement,#3 - Nino Burjanadze,#3 - United Communist Party,#3 - United Opposition,#4 - Christian-Democratic Movement,#4 - Free Georgia,#4 - Georgian Group,#4 - Labour,#4 - Republican party,#4 - Shalva Natelashvili,#5 - Davit Gamkrelidze,#5 - Free Georgia,#5 - Giorgi Targamadze,#5 - Labour,#5 - Merab Kostava Society,#5 - We Ourselves,#6 - Christian Democratic Alliance,#6 - Georgian Politics,#6 - Giorgi (Gia) Maisashvili,#6 - Industry Will Save Georgia,#6 - Koba Davitashvili,#6 - Movement for Fair Georgia,#6 - New Rights,#7 - Future Georgia,#7 - Georgian Group,#7 - Irina Sarishvili-Chanturia,#7 - Movement for Fair Georgia,#7 - Right Wing Alliance Topadze Industrialists,#7 - Zurab Kharatishvili,#8 - Freedom Party,#8 - Georgian Group,#8 - Georgian Politics,#8 - Labour,#8 - Labour Council of Georgia,#8 - Movement for Fair Georgia,#8 - National Democratic Party of Georgia,#8 - New Rights,#8 - Our Country,#8 - People's Party,#8 - Public Movement,#8 - Sergo Javakhidze,#8 - Sportsman's Union,#9 - Christian Democratic Alliance,#9 - Levan Chachua,#9 - Merab Kostava Society,#9 - National Party of Radical Democrats of Georgia,#9 - Sportsman's Union,#9 - Traditionalists - Our Georgia and Women's Party,Average votes per minute (08:00-12:00),Average votes per minute (12:00-15:00),Average votes per minute (12:00-17:00),Average votes per minute (15:00-20:00),Average votes per minute (17:00-20:00),Election,Invalid Ballots (%),More Ballots Than Votes (#),More Votes Than Ballots (#),Overall Results,Total Voter Turnout (#),Total Voter Turnout (%)
    Precinct,1,79-1,,,,71.84,,,,,,,,,,,,,,,,,,,,,20.84,,,,,,,,,,,,,2.44,,,,2.22,,,,,,,,,0.89,,,,1.77,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2008 Adjara Supreme Council - Majoritarian,,,,United National Movement,451,30.85
    Precinct,10,79-10,,,,74.32,,,,,,,,,,,,,,,,,,,,,8.3,,,,,,,,,,,,,3.86,,,,5.98,,,,,,,,,1.54,,,,5.98,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2008 Adjara Supreme Council - Majoritarian,,,,United National Movement,518,37.11
    Precinct,11,79-11,,,,74.28,,,,,,,,,,,,,,,,,,,,,15.75,,,,,,,,,,,,,1.31,,,,5.25,,,,,,,,,1.31,,,,2.1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2008 Adjara Supreme Council - Majoritarian,,,,United National Movement,381,31.94
    ...

und das ist das Mapping:

    Giorgi Margvelashvili,Georgian Dream
    Mikheil Saakashvili,United National Movement
    United National Movement,United National Movement
    Nino Chanishvili,Initiative Group
    Sportsman's Union,Sportsman's Union
    Georgian Group,Georgian Group
    Mamuka Chokhonelidze,Initiative Group
    Sergo Javakhidze,Movement for a Fair Georgia
    Traditionalists - Our Georgia and Women's Party,Traditionalists - Our Georgia and Women's Party
    Our Country,Our Country
    Giorgi Chikhladze,Initiative Group
    Merab Kostava Society,Merab Kostava Society
    Mamuka Melikishvili,Initiative Group
    Public Movement,Public Movement
    Avtandil Margiani,Initiative Group
    Labour Council of Georgia,Labour Council of Georgia
    People's Party,People's Party
    Akaki Asatiani,Union of Georgian Traditionalists
    Nestan Kirtadze,Initiative Group
    Nugzar Avaliani,Initiative Group
    Tamaz Bibiluri,Initiative Group
    Davit Bakradze,United National Movement
    Georgian Dream,Georgian Dream
    Levan Gachechiladze,Initiative Group
    United Opposition,United Opposition
    Teimuraz Mzhavia,Christian Democratic People's Party
    Mikheil Saluashvili,Initiative Group
    Kartlos Gharibashvili,Initiative Group
    Teimuraz Bobokhidze,Initiative Group
    Arkadi (Badri) Patarkatsishvili,Initiative Group
    Christian-Democratic Movement,Christian-Democratic Movement
    Labour,Labour
    Nino Burjanadze,Democratic Movement – United Georgia
    Christian Democratic Alliance,Christian Democratic Alliance
    New Rights,New Rights
    Shalva Natelashvili,Labour Party
    Davit Gamkrelidze,New Right
    Giorgi Targamadze,Christian-Democratic Movement
    National Party of Radical Democrats of Georgia,National Party of Radical Democrats of Georgia
    Republican party,Republican party
    Free Georgia,Free Georgia
    Georgian Politics,Georgian Politics
    Giorgi (Gia) Maisashvili,Party of the Future
    Koba Davitashvili,People's Party
    Movement for Fair Georgia,Movement for Fair Georgia
    Right Wing Alliance Topadze Industrialists,Right Wing Alliance Topadze Industrialists
    Irina Sarishvili-Chanturia,Hope party
    Zurab Kharatishvili,European Democrats
    Future Georgia,Future Georgia
    Levan Chachua,Initiative group
    National Democratic Party of Georgia,National Democratic Party of Georgia
    Freedom Party,Freedom Party
    Giorgi Liluashvili,Initiative group


Versuchen Sie es im Moment:

    import csv
    file = 'parties_and_candidates.csv'
    with open(file) as fh:
        dictionnary = csv.DictReader(fh, delimiter=',')
   
    df = pd.read_csv("distrcit.csv")
    df = df.rename(columns = dictionnary)


Aber die Spalten sind nicht genau gleich und wie kann ich hinzufügen, wenn es im Dictionary die gleichen Namen gibt?

von

Bitte logge dich ein oder registriere dich, um die Frage zu beantworten.

Ein anderes Problem?

Stell deine Frage

Willkommen bei der Stacklounge! Stell deine Frage sofort und kostenfrei

x
Made by a lovely community
...