简体   繁体   English

在列的开头和结尾添加字符

[英]Add character in beginning and end of column

Im trying to add " in the beginning and end of the column in a df.我试图在 df 列的开头和结尾添加"

Eg - Initial dataframe:例如 - 初始 dataframe:

A       B
Hello   What
I       Is
AM      MY

Output: Output:

A       B
Hello   "What
I       Is
AM      MY"

You could use iat to index on the specific strings, and format them with:您可以使用iat对特定字符串进行索引,并使用以下格式对其进行格式化:

df.iat[0,1] = f'"{df.iat[0,1]}'
df.iat[-1,1] = f'{df.iat[-1,1]}"'

print(df)

       A      B
0  Hello  "What
1      I     Is
2     AM    MY"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM