Reformat a single column dataset in python to a standard long format dataset

Viewed 28

I have a dataset like this, with unformatted dates and some events happened in that date, I would like to tidy it up from this:

              date                           event
0   giovedì, 18 novembre 2010       giovedì, 18 novembre 2010
1       
2   MELA Mela Sciences FDA Panel    MELA Mela Sciences FDA Panel
3   martedì, 7 dicembre 2010        martedì, 7 dicembre 2010
4       
5   OREX Orexigen Therapeutics      OREX Orexigen Therapeutics
6       
7   SLXP SALIX PHARMACEUTICALS      SLXP SALIX PHARMACEUTICALS
8   giovedì, 9 dicembre 2010        giovedì, 9 dicembre 2010

to this:

enter image description here

any idea?

First I tryed to get rid of empy lines, but I can't, i used this:

nan_value = float("NaN")
fda.replace("", nan_value, inplace=True)
fda.dropna(subset = ["date"], inplace=True)

Then I want to iterate over row to see if they contain a date or not, but I can't see how select subsequent rows before the next date and assigning it to the event column

days=['lunedì','martedì','mercoledì','giovedì','venerdì','sabato','domenica']
for index, row in fda.iterrows():
  string = row['date']
  if any(ext in string for ext in days):
    eventdate = row['date']
    event= ????


0 Answers
Related