[英]Getting wrong readings when trying to plot CSV file using pandas
My csv file looks like the following:我的 csv 文件如下所示:
As you see there are 7 columns with comma separated.如您所见,有 7 列用逗号分隔。 I have spent hours to read and plot the first column starting with 31364 with the following code:
我花了几个小时阅读 plot 以 31364 开头的第一列,代码如下:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('test.csv', sep=',', header=None, names=['colA','colB','colC','colD','colE','colF','colG'])
y = df['colA']
plt.plot(y)
But the code outputs this plot which does not match the data at all:但是代码输出这个 plot 与数据完全不匹配:
I'm using Spyder with Anaconda.我正在使用带有 Anaconda 的 Spyder。 What could be the problem?
可能是什么问题呢?
Is column A all values in the 31,000 range? A 列的所有值都在 31,000 范围内吗? You're not plotting the whole file.
您没有绘制整个文件。
edit: Don't know what result you're looking for.编辑:不知道你在寻找什么结果。 In your code, the first column in your csv is used as the index to the dataframe (after you read the csv, enter 'df', no quotes, at the python prompt to see what your dataset looks like. If you don't want the first column in the csv as an index, add 'index_col=False', no quotes, to the parameters when you read the csv in. Also, not a good idea to end lines in a csv wit the delimiter, comma in this case.
In your code, the first column in your csv is used as the index to the dataframe (after you read the csv, enter 'df', no quotes, at the python prompt to see what your dataset looks like. If you don't想要 csv 中的第一列作为索引,当您读取 csv 时,将“index_col=False”添加到参数中案子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.