在需要把df導出時,往往只需要其中的某幾列( 行 )。可以使用列表或者切片,相當於先做一個小的df,然后導出即可。
指定列:
powder[['是否進口','產地']].to_excel(r'D:\數據表\結果B.xlsx' )
powder.loc[:,'月份':'產地'].to_excel(r'D:\數據表\結果B-去重-產品類型-字段-垃圾-3.xlsx' )
powder.iloc[:,0:8].to_excel(r'D:\數據表\結果B-去重-產品類型-字段-垃圾-2.xlsx' )
指定行:
powder[0:8].to_excel(r'D:\數據表\結果B.xlsx' )
作為對比,把excel中的某幾列導入df時,使用 usecols=[] 指定即可。
junk_url = pd.read_excel(r'D:\資料包\垃圾數據-匯總庫.xlsx',sheet_name='奶粉',usecols=['編號','商品名稱','商品鏈接'],index_col='編號')
