版本相關資訊:
Python版本:Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Pandas版本:0.19.2
系統版本:Windows 10
Pandas版本:0.19.2
系統版本:Windows 10
將 dataframe 寫入 csv 檔案
import pandas as pd
# Windows路徑的寫法
file_path=r'E:\download\tmp\test.csv'
# 相對路徑的寫法
file_path='./tmp/test.csv'
data.to_csv(file_path,sep=',',index=False)
讀入 csv 檔案,轉成dataframe
import pandas as pd
# Windows路徑的寫法
file_path=r'E:\download\tmp\test.csv'
# 相對路徑的寫法
file_path='./tmp/test.csv'
df_name= pd.read_csv(file_path,sep=',')
如果輸入時,出現以下錯誤: OSError: Initializing from file failed 將engine由C改為python
import pandas as pd
file_path=r'E:\download\tmp\test.csv'
df_name= pd.read_csv(file_path ,engine='python')
若要修改輸出的編碼:
import pandas as pd
# utf-8
file_path=r'E:\download\tmp\test.csv' df_name.to_csv(file_path, encoding ='utf-8')
# Big5
file_path=r'E:\download\tmp\test.csv' df_name.to_csv(file_path, encoding ='Big5')
沒有留言:
張貼留言