简体   繁体   English

尝试使用 pandas 文件 CSV 文件时出现错误读数

[英]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.

相关问题 尝试使用 Pandas 打开 CSV 文件未找到 - File Not Found trying to open CSV using Pandas 尝试使用熊猫读取csv文件时,出现文件未找到错误。 我确定我使用了正确的文件路径 - I am getting a file not found error when trying to read a csv file using pandas. I am sure I have used the correct path to the file 如何用熊猫绘制CSV文件? - How to plot a csv file with pandas? 试图制作 csv 文件的 plot - Trying to make a plot of a csv file 尝试从 csv 文件中尝试 plot 时出现索引错误 - Index error when trying to plot from a csv file 使用Pandas DataFrame和Matplotlib将CSV文件中的数据处理到绘图中 - Using pandas dataframe and matplotlib to manipulate data from a csv file into a plot 使用 Pandas 从 CSV 文件中绘制 4 列的 CDF - Plot CDF of 4 columns from a CSV file using pandas 如何使用Pandas绘制CSV文件的字符串和浮点值的直方图 - How to plot histogram of string and float value of a csv file using Pandas Python:使用熊猫导入csv。 尝试绘制列,但给我一个错误,提示“没有要绘制的数值数据” - Python: Using pandas to import csv. Trying to plot a column but gives me an error saying “no numerical data to plot” 使用熊猫加载时,更改csv文件中的值。 (试图了解博客上显示的代码) - Changing the values in csv file when loaded using pandas. (Trying to understand a code presented on a blog)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM