首页 > 解决方案 > 在python中将数据框行转换为没有列索引的值字符串

问题描述

我有一个数据框行,并希望将其作为仅包含值的字符串,没有列。

col1 | col2 | col3
-----------------
1    | 2    | 3
x    | y    | z

我希望能够只选择一行并将其作为字符串,例如:

'1','2','3'

但是我不断地得到列名,或者很多其他值,比如:

"['1' '2'\n '3']"

标签: python-3.xpandas

解决方案


只需使用

df.iloc[1,:].to_string(header=False, index=False)
  1. header = False --> 不要在输出字符串中包含列名

  2. index = False --> 不要在输出字符串中包含行索引


推荐阅读