python-3.x - 在python中将数据框行转换为没有列索引的值字符串
问题描述
我有一个数据框行,并希望将其作为仅包含值的字符串,没有列。
col1 | col2 | col3
-----------------
1 | 2 | 3
x | y | z
我希望能够只选择一行并将其作为字符串,例如:
'1','2','3'
但是我不断地得到列名,或者很多其他值,比如:
"['1' '2'\n '3']"
解决方案
只需使用
df.iloc[1,:].to_string(header=False, index=False)
header = False --> 不要在输出字符串中包含列名
index = False --> 不要在输出字符串中包含行索引
推荐阅读
- python - 寻找避免“列表索引超出范围错误”的方法
- rust - 在特征实现中未指定关联类型
- excel - Excel VBA,通过范围加速 For 循环
- xml - XSL 动态 XPath 评估
- excel - 尝试将公式向下拖动时,对索引行引用有什么建议吗?
- python - 我们如何在 pyspark 中获取数据帧的每个分区的样本?
- python - 从 df 列 pandas 中的每个日期减去日期范围
- amazon-web-services - 将 s3 整个存储桶从 IntelligentTiering 移动到 STANDARD + 永久取消归档整个存储桶
- r - 当我尝试在 R 上安装一些软件包时出现奇怪的问题
- c - XCB如何获取原子的值