python - 如何使用 Pandas 将我的数据导入到 xlsx 文件中的表中?
问题描述
我对 Pandas 很陌生,想知道是否有一种方法可以让我获取我想要的数据并将其作为表格放入 xlsx 文件中。
这是我到目前为止的代码:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
from openpyxl import load_workbook
#defining the excel file and the sheet(s) and printing them
excel_file_1 = 'Incident Report.xls'
df_first_shift = pd.read_excel(r'C:\Users\M\Downloads\Incident Report.xls')
print(df_first_shift)
#combining all the data from the sheets into one file
df_all = pd.concat([df_first_shift])
#Creating the .xlsx file
df_all.to_excel(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx')
#Deleting a row
wb = load_workbook(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx')
ws = wb['Sheet1']
ws.delete_cols(1)
wb.save(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx')
解决方案
推荐阅读
- java - Serenity Headless Chrome 偶尔崩溃,而 Non-headless Chrome 从不崩溃
- javascript - 使用 redux 中的钩子调度操作时写入依赖数组的正确方法
- python - 绘图上的 GUI 按钮,用于选择绘图点并存储在不同的数组中
- localhost - Fiddler localhost URL(带有端口号)在带有 IIS Express 的 Visual Studio 中不起作用
- python - 根据下一行查找上一行值
- javascript - 获取html元素上的元素id名称
- python - 蟒蛇查找路径
- javascript - D3.js v5 - 从数组长度附加关于圆的线
- c++ - 成功的取消引用似乎会导致潜在的段错误
- c# - MySql Long Running Query Fails on Docker .NET Core: Attempted to read past the end of the stream / Expected to read 4 header bytes but only received 0