0

I've written the following code to read a CSV file and parse the data down to a numpy array. However, I only want the 6th number from each array. I wondered if I could do it in the string spilt method before converting it to a numpy array but couldn't get anything to work.

data = pd.read_csv('pbhistory.csv')
data['date'] = pd.to_datetime(data.date, infer_datetime_format=True)
data.sort_values(by='date', ascending=True, inplace=True)
df = pd.DataFrame(data.numbers)
df2 = df['numbers'].str.split(' ', expand=True)
df3 = pd.DataFrame(df2).to_numpy()

I get the following output:

[['17' '22' '36' '37' '52' '24']
 ['14' '22' '52' '54' '59' '04']
 ['05' '08' '29' '37' '38' '34']
 ['10' '14' '30' '40' '51' '01']
 ['07' '08' '19' '26' '36' '15']]

What I would like is the 6th or last number from each array. For example, 24, 04, 34, 01, and 15 from the array above.

user2643864
  • 641
  • 3
  • 11
  • 24

0 Answers0