任务要求
(1)读取dwd_att_wiu_base_df.csv文件;
(2)读取cert_sta字段;
(3)替换cert_stae字段中的数字为2;
(4)将修改好的字段写到新文件。
1.读取csv文件
#使用pandas读取csv文件
import pandas as pd
file = 'dwd_att_wiu_base_df.csv'
df = pd.read_csv(file)
print(df)
2.读取固定字段
cert_sta = df["cert_sta"]
print(cert_sta)
3.替换相关字符
cert_sta.replace(1,2,inplace=True)
print(cert_sta)
4.写到新文件中
df = df.replace(cert_sta)
print(df["cert_sta"])