python 读取 修改原csv文件

 修改一下后的使用df修改csv文件

enumerate是真好用呀

#-*- coding : utf-8-*-
# coding:unicode_escape
import pandas as pd
import numpy as np
import csv
# with open('333.csv',"w+") as f:
#     ff = csv.writer(f)
df = pd.read_csv('2005_train_ADD.csv', encoding='UTF-8',header=None)
# df = pd.read_csv('333.csv', encoding='UTF-8',header=None)
print(df.shape)
data = np.asarray(df)
# data[0][0] = 777stuidtonumber     skilltonumber   questiontonumber
df1 = pd.read_csv('questiontonumber.csv', encoding='UTF-8',header=None)
# df1 = pd.read_csv('444.csv', encoding='UTF-8',header=None)
print(df1.shape)
data1 = np.asarray(df1)
for x, y in enumerate(data):
    # print(y)
    for j, k in enumerate(data1):
        # print(k[0])
        if y[2] == k[0]:
            print('----')
            print(data[x][2],data1[j][1])
            data[x][2] = data1[j][1]
            # print(data)
pd.DataFrame(data).to_csv('2005_train_ADD.csv',index = False,header=None)

你可能感兴趣的:(python,numpy)