简体   繁体   English

从熊猫读取csv文件并绘图

[英]reading csv file from panda and plotting

I have 1000 files in which the data is stored in comma separation. 我有1000个文件,数据以逗号分隔存储。 The description of a file is given below: 文件说明如下:

The values are comma separated, -9999 values should be ignored and if it can be read, all the values of row and column should be stored in numbers, as it has to used in plotting. 这些值以逗号分隔, -9999值应被忽略,如果可以读取,则行和列的所有值均应以数字形式存储,因为它必须在绘图中使用。 The shape of file is [ 104 rows x 15 columns ]. 文件的形状为[ 104行x 15列 ]。

The few lines of the files are as follows: 文件的几行如下:

0,   9.8597e+00, 129.944,   1.071, 6.7433e-06, 1.0911e-05,      -9999,      -9999, 3.7134e-07, 3.5245e-05,      -9999,      -9999,  26.295,   -86.822,  -123.017



0,   8.7012e+00, 130.908,   0.966, 1.9842e-06, 1.0799e-05,      -9999,      -9999, 3.5888e-07, 7.8133e-05,      -9999,      -9999,  27.140,   -86.818,  -122.322

After reading into numeric values, I need to plot it into subplot also. 读入数值后,我还需要将其绘制到子图中。 Like COl1 vs Col2 , Col3 vs col5 and so on.... 像COl1 vs Col2,Col3 vs col5等等...

Any idea how to achieve it? 知道如何实现吗?

import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt

df1=pd.read_csv("small_file_106.txt",header=1)
print(df1)

I never used plot ,but following would be useful for the first question input the list of values to na_values and those will be considered as NA by pandas 我从未使用过plot,但是以下对第一个问题输入na_values的值列表很有用,而pandas会将其视为NA

pd.read_csv(File, sep=',',na_values=['-9999'],keep_default_na=False)

Also pd.to_numeric is available to convert data to numeric 还可以使用pd.to_numeric将数据转换为数字

df.apply(lambda x: pd.to_numeric(x, errors='ignore'))

读完(Shijo的方法看起来不错)中的数据后, Seaborn库的对图应生成所需的图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM