2017-06-20 13 views
1

Ich muss Python und Angular JS verwenden, um eine CSV-Datei von Python an die Webseite zu senden und sie entsprechend anzuzeigen.Vergleichen Sie zwei csv und führen Sie sie zusammen

Ich habe 2 CSV-Dateien bekam mit Feldern als

CSV1

Country code,Telecom,Latency 

919618, India Private Mobile,0.008800 

919619, India Private Mobile,0.008800 

919620, India Private Mobile,0.008800 

CSV2

Country code,Telecom,Latency 

919802, India Private Mobile,0.008400 

919803, India Private Mobile,0.008400 

919620, India Private Mobile,0.008400 

Die Webseite sollte als

Country code,Telecom,Latency 

919618, India Private Mobile,0.008800 

919619, India Private Mobile,0.008800 

919802, India Private Mobile,0.008400 

919803, India Private Mobile,0.008400 

919620,India Private Mobile,0.008400,0.008800 

(die letzte Anzeige Zeile enthält zwei Werte cause die CSV-Datei enthält 919620 commons in beiden)

So, jetzt bin ich neu in Angular JS und Flask, führen Sie mich einfach wie zu starten?

begann dieses mit

import pandas as pd 
import numpy as np 


dfa = pd.read_csv('rate4.csv', names=['Country Code', 'SP', 'Rate']); 
dfb = pd.read_csv('rate3.csv', names=['Country Code', 'SP', 'Rate']); 
+0

Mögliche Duplikat [Merging 2 csv-Dateien] (https://StackOverflow.com/questions/16265831/merging-2-csv-files) –

Antwort

1

Sie für die Ausgabe DataFrame Verwendung concat und groupby durch Spalten Country code und Telecom mit join Spalte Latency verwenden können:

df = pd.concat([df1, df2]) \ 
     .groupby(['Country code','Telecom'])['Latency'] \ 
     .apply(lambda x: ','.join(x.astype(str))) \ 
     .reset_index() 
print (df) 
    Country code    Telecom  Latency 
0  919618 India Private Mobile   0.0088 
1  919619 India Private Mobile   0.0088 
2  919620 India Private Mobile 0.0088,0.0084 
3  919802 India Private Mobile   0.0084 
4  919803 India Private Mobile   0.0084 
+0

Traceback (letzten Anruf zuletzt): Datei "C:/Benutzer/Yash Kumar Atri/PycharmProjects/untitled/test/prettyprint.py", Zeile 12, in df = pd.concat ([dfa, dfb]). Groupby (['Ländercode', 'Telecom']) ['Latenz']. Join (lambda x: ','. Join (x.astype (str))) Datei "C: \ Programme \ Python36 \ lib \ site-packages \ pandas \ core \ groupby.py ", Zeile 551, in __getattr__ (type (self) .__ name__, attr)) AttributError: 'SeriesGroupBy' Objekt hat kein Attribut 'Join' –

+0

Sorry, es war falsch, jetzt funktioniert es. – jezrael

+0

hey können Sie mir empfehlen, etwas zu auf einmal ganze Anzeige von Daten weil es 28 233 GHANA 29 234 NIGERIA 0,0088 FIXED ... ... ... ... 20431 91612794 Indien 0,0084 20432 91674791 Indien Feste FIXED 0,0088 Anzeige Fixed 0.0084 verursacht es Tripelpunkte zwischen –

Verwandte Themen