Reputation: 1
I'm scraping data from the website clinicaltrial.gov with pytrial and the retrieved data is a table of list.
I need to convert it to a string format when there's only one item on the list so I made a simple function to convert the List to a string.
def convertListString(List):
newList=List
if len(List)==1:
newList = List[0]
return newList
It's working well when I'm using the apply function on a single column.
df['NCTId'].apply(convertListString)
But when I'm using it on the dataFrame, it returns the same dataframe without any errors and without formatting.
df.apply(convertListString)
Edit: It works when I apply a function that just multiply the object by 2
Thanks for your help
Upvotes: 0
Views: 67
Reputation: 30070
DataFrame.apply(func)
passes column to func
by default, you may want DataFrame.applymap
df.applymap(convertListString)
Upvotes: 1