从excel上传数据到Python

  • 本文关键字:Python 数据 excel python
  • 更新时间 :
  • 英文 :


我正在尝试使用github上编写的程序。

作者提供了一个使用随机数据运行代码的示例。

xy = pd.DataFrame(np.random.normal(0, 1, (500, 3)), columns=["x_0", "x_1", "x_2"])
xy["y"] = xy.sum(axis=1) + np.random.normal(0, 1, 500)
# set a unique and monotonically increasing index (default index would suffice):
xy.index = pd.date_range("2021-04-19", "2022-08-31").map(lambda x: x.date())

是否有一种简单的方法来上传excel文件并获得与此相同的标签?

您可以使用pd.read_excel来加载excel文件:

xy = pd.read_excel("/path/to/file")

建议将数据存储为.csv格式。你仍然可以在excel中打开它,它的存储效率要高得多。

最新更新