0

i have my dataframe in pandas something like this :

this is df_proto

   proto                time

8 838,1691461,1690623 May 23 2018 06:31:52 GMT

28 838,1691470,1690632 May 23 2018 06:32:02 GMT

49 838,1691471,1690633 May 23 2018 06:32:12 GMT

70 838,1691474,1690636 May 23 2018 06:32:22 GMT

i want values of proto to split into columns and each value get converted to an int or float.

the code that i tried is this:

df_proto=df3.loc[df3.proto.notnull(),['proto','time']].copy()

df_proto.proto.str.split(',').str[2].astype(int) # here i have to specify which part of proto to convert into int. and also i am not able to add this in the df_proto. and i dont know how many values proto will contain but it is sure that all proto will have same number of value.

please help me with this.

Shivom Kumar
  • 21
  • 1
  • 1
  • 3
  • I think need `df = df3[['time']].join(df3['proto'].str.split(',',expand=True))` – jezrael Jun 12 '18 at 09:14
  • it worked . but now there are two problems. first when i am doing df.dtypes, all the columns have type object. i tried converting type of time to string using astype but still under dtypes its type is shown as object. Secondly , how am i supposed to access the values of new columns created ? their name is 0,1,2. none of df['0'] or df.0 is working. – Shivom Kumar Jun 12 '18 at 09:55
  • Need `df[0]`, also maybe help [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) – jezrael Jun 12 '18 at 10:19

0 Answers0