I have a table with a list of scientific names that I want to replace with their generic names. I found the unique values in the list, exported to CSV, opened in excel and then wrote in their corresponding generic names. Like Biceps Brachiis is Biceps. Then I reimported into pandas to replace all the scientific names in the table with the generic names.
My issue came in coverting my two lists into a dictionary to use the panda.DataFrame.replace() function. StackOverflow to the rescue yet again! I’m am beyond happy the owners of this website have decided to always make this free. Continue reading →
I’m importing a CSV file that contains lists within the rows. Pandas is importing the columns as strings and i need to convert them back to lists! Thankfully the list contents themselves are strings.
After searching around, I discovered that I can delete the brackets and then split the string on the commas. Deleting the brackets was proving tough because I need to delete “[” and “]”. In R, I’m comfortable enough with regex in the gsub function but still getting comfortable doing ANYTHING in Python. Rather than import re or string, I went with the below answer.
Those were my initial thoughts but thought I was being lazy. Sometimes finding a specific way to complete a task is easier than a generic way. I’m sure re or string would have looked more compact but I’m just ready for my columns to be imported!!