python csv读写

csv读写

写入

#列表数据存入csv
'''
数据
['Name', 'Type 1', 'Type 2', 'Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Stage', 'Legendary']
[ ['Charmander', 'Fire', 'NaN', '309', '39', '52', '43', '60', '50', '65', '1', 'False'], ['Charmeleon', 'Fire', 'NaN', '405', '58', '64', '58', '80', '65', '80', '2', 'False']]

'''
import csv
with open('test.csv','w')as f:
    f_csv = csv.writer(f)
    f_csv.writerow(row_name)
    f_csv.writerows(data)
View Code

读取

import pandas
data=pandas.read_csv("cars.csv")
View Code
原文地址:https://www.cnblogs.com/huay/p/11736894.html