python学习——pandas数据清洗

本次学习主要针对pandas下的dataframe数据结构进行,采用数据为之前下载过的iris鸢尾花数据,首先利用pd.read_csv()读取原表格数据。需要将原表格放在py文件的同目录下方便读取。

file_path = "D:\Anaconda3\envs\pytorch\projects\Pandas学习\iris.csv"
data_before = pd.read_csv(file_path,header=0,index_col=0,encoding="gbk")
data_after = data_before.iloc[0:10,0:10]#这里利用iloc切片截取了0-9行的数据
print('原始数据:\n{}'.format(data_after))
print('数据大小:{}\n'.format(data_after.shape))

啊啊去
接下来通过获取行、列标签(方便之后利用loc定位)+np.random随机函数获取随机darray数组用以产生nan空值。

index = data_after.index
col_in = data_after.columns
#print('{}\n{}'.format(index,col_in))

random_t = 10*np.random.random([4,4])
#print(random_t)
random_i = np.floor(random_t)#产生相应整数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值