我需要使用Python和Angular JS将一个CSV文件从python发送到网页并相应地显示它。
我有2个CSV文件,字段为
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
网页应显示为
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
(最后一行包含两个值,导致CSV文件包含919620个公共区域)
所以现在我是Angular JS和Flask的新手, 只是指导我如何开始?
从这个
开始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 :(得分:2)
您可以使用列DataFrame
和Country code
以及Telecom
列join
的输出Latency
使用concat
和groupby
:
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