wwjdm
wwjdm

Reputation: 2596

How to extract values from pandas Series without index

I have the following when I print my data structure:

print(speed_tf)

44.0   -24.4
45.0   -12.2
46.0   -12.2
47.0   -12.2
48.0   -12.2
Name: Speed, dtype: float64

I believe this is a pandas Series but not sure

I do not want the first column at all I just want

-24.4
-12.2
-12.2
-12.2
-12.2

I tried speed_tf.reset_index()

  index  Speed
0 44.0   -24.4
1 45.0   -12.2
2 46.0   -12.2
3 47.0   -12.2
4 48.0   -12.2

How can I just get the Speed values with index starting at 0?

Upvotes: 23

Views: 50289

Answers (4)

arilwan
arilwan

Reputation: 3993

This is for anyone willing to create a dataframe having 2 columns: series indices and series values.

# firstColumnName you choose to give
df = pd.DataFrame({'firstColumnName': speed_tf.index, 'Speed': speed_tf.values})

Upvotes: 1

Doc
Doc

Reputation: 103

To print only the Speed values, with no indices:

print(speed_tf.to_string(index=False))

Upvotes: 6

Shubham Sharma
Shubham Sharma

Reputation: 71707

Simply use Series.reset_index and Series.to_frame:

df = speed_tf.reset_index(drop=True).to_frame()

Result:

# print(df)

   Speed
0  -24.4
1  -12.2
2  -12.2
3  -12.2
4  -12.2

Upvotes: 5

Igor Rivin
Igor Rivin

Reputation: 4864

speed_tf.values 

Should do what you want.

Upvotes: 33

Related Questions