【发布时间】:2017-11-20 20:16:26
【问题描述】:
我是 Python 新手,我需要导入以空格分隔的数据。
数据看起来像这样:
Title one
Title two
Title three
Title four
1.2944870E-03 7.1226442E-01
3.8834610E-03 8.3775342E-01
6.4724353E-03 1.0313828E+00
9.0614092E-03 7.7915078E-01
2.2006279E-02 1.1677371E+00
我需要在导入过程中跳过前 4 行。
到目前为止,我有这个:
# Get .txt file
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(filetypes=[("Two Column txt","*.txt"),("Any text file","*.*")])
# Read the data
import pandas as pd
data = pd.read_csv(file_path,skiprows=4)
使用 pd.read_csv 导入后,数据为 [x_amount of rows, 1 column]。 我想知道是否有人可以告诉我如何将其分开并将第一列分配给 X 并将第二列分配给 Y
最好的问候!
【问题讨论】:
标签: python pandas data-import