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>使用while循环,它将如下所示:</p> <pre><code>rows = df.shape[0] i = 0 while i < rows: df.iloc[i,:]['description'] = '"' + df.iloc[i,:]['description'] + '"' i = i+1 </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
5 回答
将Pandas数据帧转换为scipy稀疏矩阵
7 回答
将Pandas数据帧转换为Spark Datafram时出现问题
7 回答
将pandas数据帧转换为spark DataFram时出错
10 回答
将Pandas数据帧转换为spark datafram时收到错误
4 回答
将Pandas数据帧转换为Spark数据帧
6 回答
将Pandas数据帧转换为Tensorflow数据
9 回答
将Pandas数据帧转换为tkinter obj
9 回答
将pandas数据帧转换为XML
4 回答
将Pandas数据帧转换为值sql语句
6 回答
将pandas数据帧转换为元组
7 回答
将pandas数据帧转换为元组列表
10 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
8 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
4 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
9 回答
将pandas数据帧转换为内存中类似文件的对象?
5 回答
将Pandas数据帧转换为内存功能(&F)
2 回答
将pandas数据帧转换为列表列表
8 回答
将pandas数据帧转换为列表列表以输入到RNN
10 回答
将Pandas数据帧转换为单行DataFram
4 回答