1
我有一個數據幀,其中一些列我JSON數據,這樣在列表錯誤Python的熊貓數據幀JSON轉換器
A Ferry_values
Ferry {"0": 3.4796488185359, "1": 0, "2": 0, "3": 4.4588689023021,
"4":0, "5":0,"6": 2.3752536905642, "7": 3.7376712853646, "8": 0}
使用Python中:
import json
df.ferry_values = df.ferry_values.apply(lambda x: json.loads(x).values())
在輸出列表如下:
[0,3.479649,4.458869, 0, 0, 0, 3.737671,2.375254,0]
解碼Json文件時出現錯誤。
你能幫我解決這個問題嗎?
預先感謝
沒有錯誤,所有工作正常,但Json數據未正確轉換。 – user7311536
請使用:https://www.tutorialspoint.com/execute_python_online.php 編譯代碼: 進口JSON 字符串=「{ 「1」:3.4796488185359, 「2」:0,1 「3」:0 ,「4」:4.4588689023021,「5」:0,「6」:0,「7」:2.3752536905642,「8」:3.7376712853646,「9」:0}' print(json.loads(string).values ()) 正如你將看到編譯器將回答解碼Json的錯誤 – user7311536
對我來說很好。只需注意python 2和3之間'print'語句的區別。 – pansen