[英]How to add string as value for new column for dataframe
I am trying to add string value and assign to a new column for dataframe , but could not figure it out the best way to do this. 我正在尝试添加字符串值并将其分配给dataframe的新列,但无法找出执行此操作的最佳方法。
Df['new'] = "my value"
But this is not working and I couldn't understand why, can someone please explain to me ? 但这是行不通的,我不明白为什么,有人可以向我解释吗? Or how exactly can I do this in Python using pandas dataframe ? 或者我该如何在Python中使用pandas dataframe做到这一点?
Do you mean this? 你是这个意思吗
import pandas as pd
d = {'a':[1,2,3], 'b':[4,5,6]}
j = {'c':['a','hello','t']}
x = pd.DataFrame(d)
y = pd.DataFrame(j)
x.insert(2, 'c', y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.