【发布时间】:2018-01-05 10:36:47
【问题描述】:
如何将包含以下数据的文件导入 pandas DataFrame?它保存为“data.db”,一种我不熟悉的格式。
{"hostname":"136.243.73.66","ip":"136.243.73.66","port":16600,"TCPPort":15600,"UDPPort":14600,"seen":1,"connected":0,"tried":0,"weight":1,"dateTried":null,"dateLastConnected":null,"dateCreated":{"$$date":1514997141045},"isTrusted":true,"key":"5d301e5f46bb6e0db9d379c19c451cc6905c09885e5529c7a3c5d2750674db5ab8c3e714edd4fd53fee86499db4f93f8","remoteKey":null,"lastConnections":[],"_id":"FTpfNM4c4OuXAS6d"}
{"hostname":"45.77.187.45","ip":"45.77.187.45","port":16600,"TCPPort":15600,"UDPPort":14600,"seen":1,"connected":0,"tried":0,"weight":1,"dateTried":null,"dateLastConnected":null,"dateCreated":{"$$date":1514997141046},"isTrusted":true,"key":"c752b75fbc74eaba10745937d50abd2decf71c509aff49db6662a180ba76fa3f74e5118ad905adb3b6873c250270f85f","remoteKey":null,"lastConnections":[],"_id":"f6Gn2xXyoeMrSvi8"}
{"hostname":"mainnet.deviota.com","ip":null,"port":16600,"TCPPort":15600,"UDPPort":14600,"seen":1,"connected":0,"tried":0,"weight":1,"dateTried":null,"dateLastConnected":null,"dateCreated":{"$$date":1514997141048},"isTrusted":true,"key":"a923372977f65fe08f472916f671a1749963cea36701682761307af8537c52d4e2414f4e5b471898ef84a0957b5deec3","remoteKey":null,"lastConnections":[],"_id":"oVKsMubQ5rtAhfpq"}
{"hostname":"mainnet2.deviota.com","ip":null,"port":16600,"TCPPort":15600,"UDPPort":14600,"seen":1,"connected":0,"tried":0,"weight":1,"dateTried":null,"dateLastConnected":null,"dateCreated":{"$$date":1514997141049},"isTrusted":true,"key":"9aae219149f088c9295de31125fb1f39060dd4fe1540c048f2bd097375298703c43d49dc48bb609f708f8b6e2578f7f2","remoteKey":null,"lastConnections":[],"_id":"rkQpS6BimYvfDIZU"}
这是尽可能接近的,但目前标签仍在表格内。
file_path = "path_to_file/data.db"
def read_data():
with open(file_path) as f:
return [x.split(',') for x in f.readlines()]
a = read_data()
pd.DataFrame(a)
【问题讨论】:
标签: python pandas dataframe import