![](/img/trans.png)
[英]How to extract invisible comments from specific columns in excel using python
[英]How to extract the specific data from the unorganized excel file without columns)
我達到了我的極限,我的頭發越來越稀疏。 我真的需要你的幫助。
1.嘗試
我想從一個文件夾中的*.xlsx
中提取包含特定單詞“ Super Banana ”的數據行。
這是文件圖片。 [1]: https://i.stack.imgur.com/Cb3yD.png
但
2.問題
此雜亂無章的 excel 文件中沒有列。 有很多文件,我無法手動將列添加到所有文件。
我正在尋找提取方法:
包含關鍵詞“超級香蕉”的行
或者
包含關鍵字的行之前和之后的行
https://i.stack.imgur.com/Cb3yD.png
3. 我的代碼
import glob
files = glob.glob('*.xlsx')
print(files)
import pandas as pd
for file in files:
df = pd.read_excel(file).fillna(value = 0)
for row in df.values:
data = df[df[''].str.contains('Super Banana',na=False)]
data.to_excel('excel-data_find.xlsx', encoding='utf-8')
print(data)
print('Data was extracted')
使用正確的文件路徑。 示例: df = pd.read_excel('C:\\Users\\file.xlsx').fillna(value = 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.