Python Forum
HELP- DATA FRAME INTO TIME SERIES- BASIC
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP- DATA FRAME INTO TIME SERIES- BASIC
#1
Ok, so i have a data frame and i want to change it to time series.

Output:
Month Sales Inflation 0 1-Jan 266.0 1 1 2-Jan 145.9 3 2 3-Jan 183.1 5 3 4-Jan 119.3 5 4 5-Jan 180.3 4
For some reason,below code did not work.(also if anyone can explain what it means it would help a lot i just found the code from tutorial, didn't really get it)

shampoo= pd.read_csv('shampoo_with_exog.csv', index_col=[0], parse_dates= True,squeeze=True)
Since it didn't work, i am wanted to do it manually. What i want to do is only to keep the Jan,Feb,... and strip up until including '-' for all in Months column

def month_converter(month):
    months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    return months.index(month) + 1

### this is the code for the striping part which i don't know how to do!!! Then,

for i in shampoo.Month :
    month_converter(i)
    

shampoo_index = shampoo['Month'].str.index('-')

shampoo.Month = shampoo['Month'].str[(shampoo_index+1):]

for i in shampoo.Month :
    month_converter(i)
Why doesn't this work?

SOMEONE PLEASE HELP!

Error:
Can only use .str accessor with string values, which use np.object_ dtype in pandas
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping in pandas/multi-index data frame Aleqsie 3 657 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Help: Conversion of Electricity Data into Time Series Data SmallGuy 3 1,206 Oct-04-2023, 03:31 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 1,385 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Time Series Production Process Problem Mzarour 1 2,130 Feb-28-2023, 12:25 PM
Last Post: get2sid
  reduce time series based on sum condition amdi40 0 1,099 Apr-06-2022, 09:09 AM
Last Post: amdi40
  How to accumulate volume of time series amdi40 3 2,299 Feb-15-2022, 02:23 PM
Last Post: amdi40
  Exporting data frame to excel dyerlee91 0 1,623 Oct-05-2021, 11:34 AM
Last Post: dyerlee91
  Pandas Data frame column condition check based on length of the value aditi06 1 2,683 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Adding a new column to a Panda Data Frame rsherry8 2 2,119 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  grouped data frame glitter 0 1,592 Feb-02-2021, 11:22 AM
Last Post: glitter

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020