Python中文
首页
教程
问答
标签
搜索
登录
注册
循环并修改列的每个元素
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>给定这样的数据集</p> <pre><code>import pandas as pd d = {'description': ["abcd","efgh","ijkl"], 'code': ["A","K","Z"]} df = pd.DataFrame(data=d) description code 0 abcd A 1 efgh K 2 ijkl Z </code></pre> <p>我的目标是得到这个</p> <pre><code> description code 0 "abcd" A 1 "efgh" K 2 "ijkl" Z </code></pre> <p>这段代码只打印出我的目标</p> <pre><code>for row in df["description"]: #accessing to each row print(f'"{row}"') #"modifying" each row </code></pre> <p>这就是产生的原因</p> <pre><code>"abcd" "efgh" "ijkl" </code></pre> <p>我试图设置这样的东西,但它是不正确的</p> <pre><code>rows = df.shape[0] i = 0 while i < rows: f'"{df.loc[i,"description"]}"' #wrong </code></pre> <p>或者类似的</p> <pre><code>df1["description"]=df1["description"].apply(lambda ?? </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>通过行迭代,您可以执行以下操作:</p> <pre><code>for i, row in df.iterrows(): new_val = something if <condition>: new_val = something_else df.at[i,'description'] = new_val </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
2 回答
将Pandas数据帧转换为scipy稀疏矩阵
5 回答
将Pandas数据帧转换为Spark Datafram时出现问题
1 回答
将pandas数据帧转换为spark DataFram时出错
5 回答
将Pandas数据帧转换为spark datafram时收到错误
9 回答
将Pandas数据帧转换为Spark数据帧
10 回答
将Pandas数据帧转换为Tensorflow数据
6 回答
将Pandas数据帧转换为tkinter obj
1 回答
将pandas数据帧转换为XML
2 回答
将Pandas数据帧转换为值sql语句
3 回答
将pandas数据帧转换为元组
1 回答
将pandas数据帧转换为元组列表
5 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
3 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
9 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
6 回答
将pandas数据帧转换为内存中类似文件的对象?
5 回答
将Pandas数据帧转换为内存功能(&F)
9 回答
将pandas数据帧转换为列表列表
9 回答
将pandas数据帧转换为列表列表以输入到RNN
5 回答
将Pandas数据帧转换为单行DataFram
2 回答