python中用.to_csv("filename")方法将DataFrame数据帧存储为.csv文件

csv文件可以读到python中的DataFrame数据帧中,同样的DF数据也可以保存到csv文件中,具体的代码如下所示:

import pandas as pd
import numpy as np
scores = np.random.randint(0,100,size=4)
data = pd.DataFrame({
		'id':[1,2,3,4],
		'students':["Andy","Betty","Cathy","David"],
		'gender':['M','F','F','M'],
		'score':scores
	})

print(data)
data.to_csv('students_info.csv')

输出的结果如下所示:

   id students gender  score
0   1     Andy      M     68
1   2    Betty      F     57
2   3    Cathy      F     24
3   4    David      M     66
[Finished in 4.7s]

你可能感兴趣的:(python高级数据处理方法)