f9yx0du 发表于 2024-8-18 05:53:16

Numpy——IO操作与数据处理


    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1、</span>问题?</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">大<span style="color: black;">都数</span>数据并不是<span style="color: black;">咱们</span>自己构造的,存在文件<span style="color: black;">其中</span>。<span style="color: black;">咱们</span><span style="color: black;">必须</span>工具去获取,<span style="color: black;">然则</span>Numpy其实并不适合去读取处理数据,<span style="color: black;">这儿</span><span style="color: black;">咱们</span><span style="color: black;">认识</span><span style="color: black;">关联</span>API,以及Numpy不方便的<span style="color: black;">地区</span><span style="color: black;">就可</span>。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2、</span>Numpy读取</h2>genfromtxt(fname[, dtype, comments, ...]) Load data from a text file, with missing values handled as specified.<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/40802c5853f54364a7bd32420206fb34~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723900308&amp;x-signature=HYnK3JxUzkkry5mRNzYZB1AlXTw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">​</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"># 读取数据 test = np.genfromtxt("</p>./data/numpy_test/test.csv", delimiter=,)

    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">3、</span><span style="color: black;">怎样</span>处理缺失值</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.1什么是缺失值</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">什么时候numpy中会<span style="color: black;">显现</span>nan:当<span style="color: black;">咱们</span>读取本地的文件为float的时候,<span style="color: black;">倘若</span>有缺失(<span style="color: black;">或</span>为None),就会<span style="color: black;">显现</span>nan</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.2缺失值处理?</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">那样</span>,在一组数据中单纯的把nan替换为0,合适么?会带来什么样的影响?</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">例如</span>,<span style="color: black;">所有</span>替换为0后,替换之前的平均值<span style="color: black;">倘若</span>大于0,替换之后的均值肯定会变小,<span style="color: black;">因此</span>更<span style="color: black;">通常</span>的方式是把缺失的数值替换为均值(中值)<span style="color: black;">或</span>是直接删除有缺失值的一行</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">因此</span>:</p><span style="color: black;">怎样</span>计算一组数据的中值<span style="color: black;">或</span>是均值<span style="color: black;">怎样</span>删除有缺失数据的那一行(列)<strong style="color: blue;">在pandas<span style="color: black;">中间商</span>绍</strong>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">t中存在nan值,<span style="color: black;">怎样</span>操作把其中的nan填充为每一列的均值 t = array([[ 0., 1., 2., 3., 4., 5.], [ 6., 7., nan, 9., 10., 11.], [ 12., 13., 14., nan, 16., 17.], [ 18., 19., 20., 21., 22., 23.]])</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">处理<span style="color: black;">规律</span>:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/f2b765aa2a50468bb6a9ec462c768fd0~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723900308&amp;x-signature=SQpxdu3cm%2FQmzBTu8gyR7y11pLM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">​</p>




j8typz 发表于 2024-10-5 07:27:15

我完全赞同你的观点,思考很有深度。

7wu1wm0 发表于 2024-10-11 11:16:21

回顾历史,我们不难发现:无数先辈用鲜血和生命铺就了中华民族复兴的康庄大道。
页: [1]
查看完整版本: Numpy——IO操作与数据处理