В Python Colab Google Как разделить CSV (TSV) файл по соответствующим столбцам? - PullRequest
0 голосов
/ 22 апреля 2020

Используя Google Colab, на этапе 1 этого кода я построил два целых столбца из файла данных, но я хочу разделить эти 2 столбца в соответствии с отображением информации в столбце № 4, который называется Типо (этап 2 этого код) Типо = OF, YF, YR, OR

Например, первые 3 и последние 3 строки моего файла имеют имя luv lx Tipo a 44.44 43.5 OF b 41.95 43.07 OF ... cc 41.28 43.67 YR около 42,07 43,74 YR Cb 43,08 43,8 ИЛИ

на первом этапе моего кода я получил этот участок enter image description here

    #Stage 1

import numpy as np
#from numpy import *
import pylab
import pandas as pd
from statsmodels.formula.api import ols
import statsmodels.api as sm
import matplotlib.pyplot as plt




SED  = pd.read_csv("luvlx.tsv", header=1, delim_whitespace=True)
# file with 4  columns
# col1 = name
# col2 = luv
# col3 = lx
# col4 = tipo

tipo=SED.ix[:,3]
lx=SED.ix[:,2]
luv=SED.ix[:,1]
name=SED.ix[:,0]



#Cambio de variable a las que queremos graficar
x = luv
y = lx


#Graficando
plt.plot(x, y, 'o')
plt.title('Grafica de datos y el mejor ajuste lineal y cuadratico')
plt.ylabel('Longitud del pendulo')
plt.xlabel('Longitud del pendulo (m)')
plt.show()

но, как сделать то же самое сюжет, используя только типо = OF? Я хочу этот новый график (только строки Типо = OF) enter image description here

    #Stage 2

# splitting by Tipo  
# Question. How to split a file according to "tipo"? 
#Tipo have 4 diferents classification: OF, YF, OR, YR



#Split in tipo = OF
luvOF=[]
lxOF=[]
#Split in tipo = YF
luvYF=[]
lxYF=[]
#Split in tipo = OR
luvOR=[]
lxOR=[]
#Split in tipo = YR
luvYR=[]
lxYR=[]



for i,j,k,l in zip(name,luv,lx,tipo):
#  j = float(j)
#  k = float(k)

# split the original file in different type accordint to Tipo
    if l == "OF" :
     luvOF.append(luv)
     lxOF.append(lx)
    if l == "YF" :
     luvYF.append(luv)
     lxYF.append(lx)
    if l == "OR" :
     luvOR.append(luv)
     lxOR.append(lx)
    if l == "YR" :
     luvYR.append(luv)
     lxYR.append(lx)




#Graficando by Tipo 
plt.plot(luvOF, lxOF, 'o')
plt.plot(luvYF, lxYF, 'g')
plt.plot(luvOR, lxOR, 'b')
plt.plot(luvYR, lxYR, 'y')
plt.title('Grafica de datos Tipo ')
plt.ylabel('Longitud del pendulo')
plt.xlabel('Longitud del pendulo (m)')
plt.show()

Я загрузил свои файлы в среду Google Colab

Код в Colab https://colab.research.google.com/drive/1gVUXMt3hcvnt0xLTsEzv5fsL5iKGPKr1

Файл с данными для построения https://drive.google.com/file/d/1qMdFS0sFRJEHBIezrkhc5dysulpFS4lI/view?usp=sharing

Я оценил любую помощь

...