小编Alb*_*rez的帖子

将json文件作为pandas dataframe读取?

我使用python 3.6并尝试使用下面的代码下载json文件(350 MB)作为pandas数据帧.但是,我收到以下错误:

data_json_str = "[" + ",".join(data) + "]
"TypeError: sequence item 0: expected str instance, bytes found
Run Code Online (Sandbox Code Playgroud)

我该如何修复错误?

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)

python json python-3.x pandas

10
推荐指数
3
解决办法
4万
查看次数

如何在同一张图中绘制两个列表,但颜色不同?

请帮我在同一张图上绘制两个列表。线条应该是不同的颜色。这是我试过的代码:

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)

python matplotlib

6
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×2

json ×1

matplotlib ×1

pandas ×1

python-3.x ×1