简体   繁体   中英

reading text file with pandas dataframe

I am trying to select the first two columns in a text file with the following structure:

# Log file
# time, ft, t, d, wx, wy
2.00000000,1.82266415,205082.33545232,501.88487172,-1.16541985,-0.97270584
3.00000000,1.82266415,205082.33545232,752.83193437,-1.16553201,-0.97285083
4.00000000,1.82266415,205082.33545232,1003.78266552,-1.16564190,-0.97299267
5.00000000,1.82266415,205082.33545232,1254.73750199,-1.16574956,-0.97313135

I would like to graph and integrate the second column over the first column, so first getting the first and second column in arrays or lists like x = [2.00, 3,00,...] and y = [1.82266, 1.822664,...]

The code I use is as follows:

data = pd.read_csv('perflog.txt', sep=" ", header=None, skiprows = 2)

data.columns = ["time", "ft", "t", "d", "wx", "wy"]

However, this raised the following: ValueError: Length mismatch: Expected axis has 1 elements, new values have 6 elements.

I am using skiprows to ignore the first two lines, anyone knows how I would obtain the arrays/list as required?

import pandas as pd

data = pd.read_csv('perflog.txt', sep=",", header=None, skiprows=2)
data.columns = ["time", "ft", "t", "d", "wx", "wy"]

print(data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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