![](/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.