下面我将如何绘制在一个大的数据帧的行31中的数据,设置行0作为x轴。(更新回答)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
创建具有32行随机阵列,和10列
df = pd.DataFrame(np.random.rand(320).reshape(32,10), columns=range(64,74), index=range(1,33))
df.to_excel(r"D:\data\data.xlsx")
只读列和行的是你想使用“parse_cols”和“skiprows”。这个例子中的第一列是数据框索引。
# load desired columns and rows into a dataframe
# in this method, I firse make a list of all skipped_rows
desired_cols = [0] + list(range(2,9))
skipped_rows = list(range(1,33))
skipped_rows.remove(31)
df = pd.read_excel(r"D:\data\data.xlsx", index_col=0, parse_cols=desired_cols, skiprows=skipped_rows)
目前,这会产生一个只有一行的数据帧。
65 66 67 68 69 70 71
31 0.310933 0.606858 0.12442 0.988441 0.821966 0.213625 0.254897
隔离只是你要绘制的行,给予与原列标题pandas.Series作为索引
ser = df.loc[31, :]
情节系列。
fig, ax = plt.subplots()
ser.plot(ax=ax)
ax.set_xlabel("year")
ax.set_ylabel("precipitation")
fig, ax = plt.subplots()
ser.plot(kind="bar", ax=ax)
ax.set_xlabel("year")
ax.set_ylabel("precipitation")
你有你的Excel电子表格的样本,你可以发布? –