1

My initial df is:

df =

    ID  location
0   141     [(45.1024, 7.7498), (45.1027, 7.75), (45.1072,...
1   403     [(45.0595, 7.6829), (45.0595, 7.6829), (45.056...
2   920     [(45.0695, 7.5454), (44.9727, 7.666), (44.9726..

after applying b = df['location'].apply(pd.Series) I get

1                   2                   3                    4
(45.1024, 7.7498)   (45.1027, 7.75)     (45.1072, 7.7568)   (45.1076, 7.7563)
...

I get partially what I want. But I'm loosing my column 'ID'. How I can save it and apply pd.Series?

Mamed
  • 1,102
  • 8
  • 23
  • include your desired output so we are clear on what you want – Yuca Aug 07 '19 at 22:38
  • 1
    Possible duplicate of [Pandas split column of lists into multiple columns](https://stackoverflow.com/questions/35491274/pandas-split-column-of-lists-into-multiple-columns) – Erfan Aug 07 '19 at 22:39
  • 1
    Dont use `apply(pd.Series)`. It's really slow. Use; `df.iloc[:, :1].join(pd.DataFrame(df['location'].values.tolist()))` – Erfan Aug 07 '19 at 22:41

1 Answers1

0
df = pd.concat([df, b], axis=1)
df = df.drop(labels=['location'], axis=1)