在本文中,我將介紹如何使用 Python 和 pandas 庫(kù)讀取、寫入文件。
1、安裝
pip install pandas
2、讀取
import pandas as pd
df = pd.read_excel('data.xlsx')
此代碼中,我們首先導(dǎo)入 pandas 庫(kù)并將其重命名為 pd。使用 pd.read_excel() 函數(shù)讀取 'data.xlsx' 文件并將其存儲(chǔ)在 df 數(shù)據(jù)幀中。
3、寫入
df.to_excel('output.xlsx', index=False)
使用 df.to_excel() 函數(shù)將 df 數(shù)據(jù)幀寫入 'output.xlsx' 文件中。參數(shù) index=False 表示不包括行號(hào)。
-
文件
+關(guān)注
關(guān)注
1文章
578瀏覽量
25235 -
函數(shù)
+關(guān)注
關(guān)注
3文章
4372瀏覽量
64321 -
代碼
+關(guān)注
關(guān)注
30文章
4891瀏覽量
70317 -
python
+關(guān)注
關(guān)注
56文章
4825瀏覽量
86304
發(fā)布評(píng)論請(qǐng)先 登錄
TensorFlow常用Python擴(kuò)展包
pandas讀取csv文件有什么方法和注意點(diǎn)?

如何通過pandas讀取csv文件指定的前幾行?
詳解Python中的Pandas和Numpy庫(kù)
介紹Python中常用的文件讀取方法以及應(yīng)用示例
介紹Python中文件創(chuàng)建與寫入的基本方法
python讀取數(shù)據(jù)庫(kù)數(shù)據(jù) python查詢數(shù)據(jù)庫(kù) python數(shù)據(jù)庫(kù)連接
如何使用Python和pandas庫(kù)操作Excel文件
如何使用Python讀取寫入Word文件
如何利用Python和pandas來處理json數(shù)據(jù)

評(píng)論