我是Python新手,需要导入空间分离的数据。从.txt文件导入数据并在Python中定义x和y变量
的数据看起来是这样的:
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行,第1列]导入之后。 我想知道如果有人能告诉我如何分离这和第一列X和第二列分配给Ÿ
祝商祺!
你好, 伴您行数据卡梅斯出这样 ' XY NaN的0.011650 NaN的0.685272 0.014239 NaN的0.725674 0.016828 NaN的0.747055 0.019417 NaN的0.848044' –
@ManuelOliveira什么是您的输入文件喜欢?它可能与您想跳过的前四行有关。我的例子符合你提供的样本。如果标题看起来不同,那么在导入熊猫之前可能应删除它们(例如,使用'tail -n +5 file_with_header.csv> file_without_header.csv') – zeevb