0

I have a dataframe in google colab when I print the dataframe this is the output I get:

                                  0
0                    Aaron Burciaga
1                             \nECS
2    \nVP Artificial Intelligence\n
3               Chanchal Chatterjee
4                    \nGoogle, Inc.
..                              ...
247                       \nI2chain
248                     \nFounder\n
249            Chandrashekar Bhat M
250                       \nTrashin
251                         \nCEO\n

However when I export the dataframe in excel I get the below output enter image description here

Can someone help me figure out how to properly export the data.

My code:

  tmpList = []
  speaker_name = soup.find_all('h4', class_ = 'clearfix Roboto-Medium font15 sbl-t t-b-   m0 dks-t l-h20' )  
  for name in speaker_name:
  print(name.text)
  tmpList.append(name.text)

  df1 = pd.DataFrame(tmpList)
  df1
  print(df1)
  df1.to_csv('sample.csv')
  files.download("sample.csv")

1 Answers1

0

The problem comes from the \n at the beginning (of some) of your values. Just strip them.In case you haven't figured it out, the values are present in each cell, but not at the first (visible) line.

So what about replacing df1 = pd.DataFrame(tmpList) by

df1 = pd.DataFrame(tmpList).applymap(str.strip)

?

keepAlive
  • 6,369
  • 5
  • 24
  • 39