文章目录

  • ​​读取ASC文件​​
  • ​​保存为CSV文件​​
  • ​​完整转换代码​​

读取ASC文件

利用pandas的​​read_csv​​​即可读取​​asc​​格式的文件:

framefile = pd.read_csv(filepath,skiprows=4,encoding="gbk",engine='python',sep=' ',delimiter=None, index_col=False,header=None,skipinitialspace=True)

保存为CSV文件

framefile.to_csv("filename.csv",index=False,sep=',')

完整转换代码

import pandas as pd

if __name__ == '__main__':
filepath = "./2021MCM/rastert_feature1.asc"
ASCfile = pd.read_csv(filepath,skiprows=4,encoding="gbk",engine='python',sep=' ',delimiter=None, index_col=False,header=None,skipinitialspace=True)
# print(ASCfile.columns)
# print(ASCfile.iloc[0:,0:1]) # 行,列 = [:, :]
# print(ASCfile)
ASCfile.to_csv("rastert_feature1.csv",index=False,sep=',')

读取后的asc文件:

python——基于Pandas读取asc文件并保存为csv格式_CSV

参考文章:

  • ​​读取asc文件​​
  • ​​python写入csv文件的几种方法总结​​