编辑:这个问题是重复的。原始问题的链接在上面发布。
我正在使用 Python 绘制一组在 Python 终端上显示良好的值(使用 Jupyter NoteBook),但是当我保存它时,保存的文件在打开时显示一张空的(全白)照片。这是我的代码:
import matplotlib.pyplot as plt
plt.plot([1,3,4])
plt.show()
plt.savefig('E:/1.png')
Run Code Online (Sandbox Code Playgroud) 在Python中,我们可以将函数的返回类型指定为
def foo() -> int:
some_int = get_some_int()
return some_int
Run Code Online (Sandbox Code Playgroud)
返回多个值时如何指定返回类型?例如,如何指定以下函数的返回类型?
def bar(): # -> ?
some_float = get_some_float()
some_int = get_some_int()
return some_float,some_int
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的 Pandas 数据框:
Date Hour Actual
2018-06-01 0 0.000000
2018-06-01 1 0.012000
2018-06-01 2 0.065000
2018-06-01 3 0.560000
...
Run Code Online (Sandbox Code Playgroud)
我想转换这些 Hour 整数索引并添加到日期,以便它是 Pandas 的 datetime 对象。结果应该是这样的:
Date Actual
2018-06-01 00:00:00 0.000000
2018-06-01 01:00:00 0.012000
2018-06-01 02:00:00 0.065000
2018-06-01 03:00:00 0.560000
...
Run Code Online (Sandbox Code Playgroud)
这样做的有效方法是什么?Panda 是否提供将整数索引转换为日期时间对象的功能?
python ×2
datetime ×1
function ×1
jupyter ×1
matplotlib ×1
pandas ×1
plot ×1
python-3.x ×1
return ×1
types ×1