import pandas as pd
df = pd.DataFrame(columns = ['a', 'b', 'c'],
data=[['A','1','http:1'],
['B', '2','http:2'],
['C', '3','http:3'],
['D','4','http:4']])
print(df)
a b c
0 A 1 http:1
1 B 2 http:2
2 C 3 http:3
3 D 4 http:4
我想输出:
#Result
G "A","1"
http:1
G "B","2"
http:2
G "C","3"
http:3
G "D","4"
http:4
这样的格式,应该怎么拼接输出啊
1
tfdetang 2022-01-21 14:38:20 +08:00
这不就是行循环一下 把每列的内容放到格式化的字符串里就行了吗
|
4
cclin 2022-01-21 16:45:40 +08:00 via Android
拿去抄吧
def combine(line: pd.Series): print(line) return f'G "{line.a}","{line.b}"\n{line.c}' df = df.apply(combine, axis=1) for s in list(df): print(s) |
5
cassidyhere 2022-01-21 16:46:09 +08:00
'G "' + df.a + '","' + df.b + '"\n' + df.c
|
6
toyst OP 感谢大家,原来输出到文本\n 就能显示换行符了
|