import os
os.makedirs(os.path.join(‘…’, ‘data’), exist_ok=True)
data_file = os.path.join(‘…’, ‘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’)
# 如果没有安装pandas,只需取消对以下行的注释来安装pandas
!pip install pandas
import pandas as pd
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
inputs, outputs = data.iloc[:, 0:2], data.iloc[:, 2]
inputs = inputs.fillna(inputs.mean())
print(inputs)
Traceback (most recent call last):
Cell In[9], line 2
inputs = inputs.fillna(inputs.mean())
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\generic.py:11556 in mean
tz : str or tzinfo or None
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\generic.py:11201 in mean
“”"
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\generic.py:11158 in _stat_function
2020-01-03 NaN NaN NaN
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\frame.py:10519 in _reduce
FutureWarning,
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\internals\managers.py:1534 in reduce
qs : list of the quantiles to be computed
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\internals\blocks.py:339 in reduce
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\frame.py:10482 in blk_func
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\nanops.py:96 in _f
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\nanops.py:158 in f
# Bottleneck uses naive summation leading to O(n) loss of precision
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\nanops.py:421 in new_func
Parameters
File D:\Anaconda\envs\DIDL\Lib\site-packages\pandas\core\nanops.py:727 in nanmean
ct_mask = count == 0
File D:\Anaconda\envs\DIDL\Lib\site-packages\numpy\core_methods.py:48 in _sum
return umr_sum(a, axis, dtype, out, keepdims, initial, where)
TypeError: can only concatenate str (not “int”) to str
runcell(0, ‘C:/Users/22052/.spyder-py3/temp.py’)
File :17
print(data)
^
SyntaxError: invalid character ‘(’ (U+FF08)