【发布时间】:2015-11-04 01:27:27
【问题描述】:
我正在尝试将 pandas 数据框的输出限制为前 3 行。但是,我得到了所有 500000 个数据点的摘要。当我在没有指定“Time [s]”作为索引的情况下运行它时,它工作正常,我只得到 3 行数据。我正在运行 Pandas 0.16.2 和 Python 3。
%matplotlib inline
import pandas as pd
from sys import platform as _platform
import matplotlib.pyplot as plt
pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier
plt.rcParams['figure.figsize'] = (15, 5)
shot1 = "C:\\Users\ELEC-LAB_1\Documents\GitHub\Black Powder\BlackPowder_Shot-1.csv"
shot1_data = pd.read_csv(shot1, parse_dates=['Time [s]'], index_col='Time [s]') # Read the data using the time as the index.
shot1_data[:3]
时间 [s] CH 1 [psi] CH 2 [psi] CH 3 [psi] CH 4 [psi] CH 5 [psi] CH 6 [psi] CH 7 [psi] CH 8 [psi] CH 9 [ psi] CH 10 [psi] CH 16 [V]
-0.200000 -0.018311 -0.054932 -0.012207 -0.054932 -0.006104 -0.048828 -0.030518 -0.018311 0.030518 -0.018311 0.011597
-0.199998 0.006104 0.109863 0.048828 0.048828 -0.018311 -0.054932 0.042725 0.054932 -0.042725 0.024414 0.010986
-0.199996 0.012207 -0.042725 0.061035 -0.097656 0.067139 0.006104 -0.054932 -0.067139 -0.097656 -0.134277 0.010986
-0.199994 0.012207 -0.006104 -0.079346 0.036621 -0.036621 0.042725 0.006104 0.067139 0.012207 -0.042725 0.011597
-0.199992 0.006104 0.067139 0.091553 0.091553 0.024414 0.012207 0.097656 -0.030518 -0.024414 0.061035 0.010986
-0.199990 0.036621 0.006104 0.061035 0.109863 0.073242 0.067139 0.109863 -0.054932 0.158691 0.000000 0.011597
500000 行 × 11 列
【问题讨论】:
-
shot1_data.head(3) -
看起来你正在做的是将索引设置为 datetimeindex 但然后尝试使用索引中不再存在的值来选择前三行进行切片:
shot1_data[:3]if你做了shot1_data.head(3)或shot1_data.iloc[:3]然后它会做你所期望的