2
我在列表中有urls。這是數據框的一個元素。我需要將這些字符串列表中的每一個轉換爲像元組這樣的可排列類型。我已經用逗號讀取了元組(a,),在轉換時保留了列表中的字符串。在應用於整列數據框時,我似乎無法使其發揮作用。概率簡單的東西將字符串列表中的數據幀列轉換爲元組
df['url'] = tuple(df['url',])
...不起作用
flatframe['url'] = flatframe['url'].apply(tuple)
...工程,但不保留字符串
這裏有幾個數據的列:
index artist ranking song songurl songtext artisturl year
2280 (Lady Antebellum,) 81 [Bartender (Lady Antebellum song)] [/wiki/Bartender_(Lady_Antebellum_song)] "Bartender (Lady Antebellum song)" /wiki/Lady_Antebellum 2014
2281 (Naughty Boy, Sam Smith) 82 [La La La (Naughty Boy song)] [/wiki/La_La_La_(Naughty_Boy_song)] "La La La (Naughty Boy song)" [/wiki/Naughty_Boy, /wiki/Sam_Smith_(singer)] 2014
2282 (Robin Thicke, T.I., Pharrell Williams) 83 [Blurred Lines] [/wiki/Blurred_Lines] "Blurred Lines" [/wiki/Robin_Thicke, /wiki/T.I., /wiki/Pharrel... 2014
2283 (Lady Gaga, R. Kelly) 84 [Do What U Want] [/wiki/Do_What_U_Want] "Do What U Want" [/wiki/Lady_Gaga, /wiki/R._Kelly] 2014
你能爲我們提供一個樣本數據看? – yesemsanthoshkumar
也許,這可能有助於... https://stackoverflow.com/questions/37994791/in-pandas-how-to-read-csv-files-with-lists-in-a-column – yesemsanthoshkumar
你能提供一個樣本你期望的輸出? –