我使用python 3.6并尝试使用下面的代码下载json文件(350 MB)作为pandas数据帧.但是,我收到以下错误:
Run Code Online (Sandbox Code Playgroud)data_json_str = "[" + ",".join(data) + "] "TypeError: sequence item 0: expected str instance, bytes found
我该如何修复错误?
import pandas as pd
# read the entire file into a python array
with open('C:/Users/Alberto/nutrients.json', 'rb') as f:
data = f.readlines()
# remove the trailing "\n" from each line
data = map(lambda x: x.rstrip(), data)
# each element of 'data' is an individual JSON object.
# i want to convert it into an *array* of JSON objects
# which, in …Run Code Online (Sandbox Code Playgroud) 请帮我在同一张图上绘制两个列表。线条应该是不同的颜色。这是我试过的代码:
import matplotlib.pyplot as plt
train_X = [1,2,3,4,5]
train_Y = [10, 20, 30, 40, 50]
train_Z = [10, 20, 30, 40, 50,25]
alpha = float(input("Input alpha: "))
forecast = [] for x in range(0, len(train_X)+1):
if x==0:
forecast.append(train_Y[0])
else:
forecast.append(alpha*train_Y[x-1] + (1 - alpha) * forecast[x-1])
plt.plot(forecast,train_Z,'g')
plt.show()
Run Code Online (Sandbox Code Playgroud)