[英]Plotting multiple figures from one excel file using pandas and matplotlib
我正在處理一個相當大的 excel 文件(超過百萬行)。 我想 plot 720 行然后跳過 43609 行然后 plot 接下來的 720 到不同的數字。 有沒有辦法做到這一點而不必在每個 plot 之前讀取文件並且仍然能夠使用 skiprows?
可能的解決方案是在 pd.read_excel 的skiprows
參數和切片中使用lambda function
pd.read_excel
所需的行創建圖。
例如,您想跳過 excel 文件中的黃色行,如下所示:
# pip install pandas
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel('data.xlsx', header=0, skiprows = lambda x: x in range(6, 11))
df
然后您可以使用切片來創建繪圖。
plt.plot(df[:4])
plt.plot(df[5:])
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.