我想了解为什么 pd.Series(Names, Scores)
以相反的顺序(分数,名称)而不是(名称,分数)生成列。
import pandas as pd
names = ['Paul', 'Tom', 'Jill']
scores = [100, 90, 80]
my_series = pd.Series(names, scores)
print(my_series)
结果是:
|100| Paul|
|90 | Tom|
|80 | Jill|
dtype: object
答案 0 :(得分:1)
检查 PIL
' 类参数文档:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html
您将 from PIL import Image
import numpy as np
img_w, img_h = 200, 200
data = np.zeros((img_h, img_w, 3), dtype=np.uint8) <- zero np_array depth 3 for RGB
data[100, 100] = [255, 0, 0] <- fille array with 255,0,0 in RGB
img = Image.fromarray(data, 'RGB') <- array to image (all black then)
img.save('test.png')
img.show()
作为数据传递,Series
作为索引传递;这就是为什么他们似乎在你的结果中“交换了位置”。
请注意 names
将生成一个一维数组(即它只有一列)。您似乎想要生成一个数据框,您需要在压缩两个列表后使用 scores
:
Series