0

I have this df:

`

                                       open       high        low      close                               Date
symbol date
GOOG   2023-01-18 09:30:00-05:00  92.940002  93.449997  92.849998  92.980003  (GOOG, 2023-01-18 09:30:00-05:00)
       2023-01-18 09:35:00-05:00  92.989998  93.070000  92.599998  92.910004  (GOOG, 2023-01-18 09:35:00-05:00)
       2023-01-18 09:40:00-05:00  92.919998  93.035004  92.400002  92.599998  (GOOG, 2023-01-18 09:40:00-05:00)
       2023-01-18 09:45:00-05:00  92.610001  92.699997  92.400002  92.677498  (GOOG, 2023-01-18 09:45:00-05:00)
       2023-01-18 09:50:00-05:00  92.680000  92.855003  92.659203  92.769997  (GOOG, 2023-01-18 09:50:00-05:00)

`

and I whant to split the last column df[Date] into symbol and date. That column type is an object.

How can I do this?

The data I have, gives indexed the symbol and date, so when making a new column from the index, it throws both together.

I've tried with this:

df[['symbol', 'date']]=df.Date.str.split(",",expand = True)

with error:

ValueError: Columns must be same length as key

and this:

df['new'] = df['Date'].str.split(',').str[0]

but both gives error

I've tried with this:

df['Date']=df['Date'].tolist()
    df['Date']=pd.DataFrame(df['Date'].tolist, index=df.index)
    df[['Symbol','Dates']] = pd.DataFrame(df['Date'].tolist(),index=df.index)

but gives error:

ValueError: DataFrame constructor not properly called!

Habi
  • 45
  • 6

0 Answers0