我从librosa库中提取了数据集。
这些数据为对象格式。
It has got '\n' and spaces and all. So, it is needed to be cleaned
Function Get_Params(ws As Worksheet, LR As Long, Target As Range) As Variant()
Dim Temp As Worksheet: Set Temp = ThisWorkbook.Sheets("Temp")
Dim LR2 As Long
ws.Range("D1:D" & LR).SpecialCells(xlCellTypeVisible).Copy
Temp.Range("U1").PasteSpecial xlPasteValues
Temp.Range("U1").RemoveDuplicates 1, xlYes
LR2 = Temp.Range("U" & Temp.Rows.Count).End(xlUp).Row
Get_Params = Temp.Range("U2:U" & LR2).Value '<--- ERROR HERE (LR2 = 2)
Temp.Range("U1").EntireColumn.ClearContents
End Function
此代码有效,但在大多数情况下会出现语法错误。
This is an error occurring in most cases.
在此之后,我想以相同的行和列格式将每个清除的数据保存到csv文件中。因此也有任何建议。
答案 0 :(得分:1)
不要替换所有空格,仅当它们在两位数之间时:
if '\n' in df['MFCC_1'][0]:
row = df['MFCC_1'][0].replace('\n', '')
row = ast.literal_eval(re.sub(r'(?<=\d)\s+(?=\d)', ",", row))