进入这里
输入如下语句
conda activate env_pytorch
python
import torch
书P26 2.2.1 读取数据集
然后进入pytorch 数据操作
先打开python
>>>import torch
>>>import os
>>>os.makedirs(os.path.join('E:', 'data'), exist_ok=True)
>>>data_file = os.path.join('E:', 'data', 'house_tiny.csv')
>>>with open(data_file, 'w') as f:
... f.write('NumRooms,Alley,Price\n')
... f.write('NA,Pave,127500\n')
... f.write('2,NA,106000\n')
... f.write('4,NA,178100\n')
... f.write('NA,NA,140000\n')
//运行出结果
>>>exit() //退出python
(env_pytorch) C:\Users\杨珊>pip install pandas
//下面是漫长的安装等待时间
漫长等待后,安装失败,看别的帖子说:
在cmd中执行命令
pip install pandas -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
用豆瓣源进行安装
原因:这种情况是因为默认从国外服务器下载的,网速很慢,就会连接超时,用国内源安装就可以
果然成功了:
安崇成功,重新输入
(env_pytorch) C:\Users\杨珊>python
Python 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.makedirs(os.path.join('E:', 'data'), exist_ok=True)
>>>> data_file = os.path.join('E:', 'data', 'house_tiny.csv')
>>> with open(data_file, 'w') as f:
... f.write('NumRooms,Alley,Price\n')
... f.write('NA,Pave,127500\n')
... f.write('2,NA,106000\n')
... f.write('4,NA,178100\n')
... f.write('NA,NA,140000\n')
21
15
12
12
13
>>> data=pd.read_csv(data_file)
>>> print(data)
NumRooms Alley Price
0 NaN Pave 127500
1 2.0 NaN 106000
2 4.0 NaN 178100
3 NaN NaN 140000