1

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?

2
  • Clearly sep=" " makes no sense. Commented Jan 19, 2022 at 14:43
  • So when I remove this, how would I go about obtaining the arrays as required? Commented Jan 19, 2022 at 14:46

1 Answer 1

1
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)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! this seems to show the dataframe as a whole. How would I obtain say the first and second column? I tried print(data[0]) but this doesnt give the first column, but a KeyError:0
I got it, I use print (data["time"])
or data.time and data.ft

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.