pandas保存数据不要行号要列号

import numpy as np
import pandas as pd

arr = np.random.randint(5,10,(5,2))

df = pd.DataFrame(arr,columns=['file','label'])
df.to_csv("test.csv",index=None)

如果需要行号,可以参考这篇文章:这里

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:wu_tianDe
# datetime:2021/7/25 14:49
# software: PyCharm
import pandas as pd

df = pd.DataFrame(columns=['name','label']) # 创建空表
for i in range(3): # 逐行追加
    name = '0001.png'
    label = 'angry'
    df = df.append(pd.DataFrame({'name':[name],'label':[label]}),ignore_index=True)

print(df)
df.to_csv("test.csv",index=None)

你可能感兴趣的:(python)