![](/img/trans.png)
[英]How to Concat a DataFrame with String to a DataFrame with Unicode and normalize datatype
[英]How to print string value from DataFrame without datatype
当我从数据框中显示一个单元格时,我得到了
df[df.a==1]['b']
Out[120]:
0 2
Name: b, dtype: int64
但是,当我想将它转换为字符串时,我得到了
str(df[df.a==1]['b'])
Out[124]: '0 2\nName: b, dtype: int64'
如何在不使用字符串操作的情况下打印没有dtype
和名称的值?
只需执行以下操作,返回的是一个pandas系列,因此您需要访问values
或name
属性:
In [2]:
df = pd.DataFrame({'a':np.arange(5), 'b':np.random.randn(5)})
df
Out[2]:
a b
0 0 -1.795051
1 1 1.579010
2 2 1.908378
3 3 1.814691
4 4 -0.470358
In [16]:
type(df[df['a']==2]['b'])
Out[16]:
pandas.core.series.Series
In [9]:
df[df['a']==2]['b'].values[0]
Out[9]:
1.9083782154318822
In [15]:
df.loc[df['a']==2,'b'].name
Out[15]:
'b'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.