我有一个带有不同数据类型值的defaultdict
defaultdict(<class 'list'>, {'id': ['042'], 'success': [1, 1, 1]})
并希望将其保存到带有pandas的文件中。
mwe代码是:
import pandas as pd
import collections
dd = collections.defaultdict(list)
dd['id'].append('42')
for x in range(3):
dd['success'].append(1)
print(dd)
pd.DataFrame(dd).to_csv('test.csv')
我得到ValueError: arrays must all be same length
。如何将列表'success'
写入一个csv单元格?
答案 0 :(得分:0)
IIUC:
使用func extractNameAndMail(in string: String) -> (name:String, email:String) {
if let rangeOfLessThan = string.range(of: "<") {
let email = string[rangeOfLessThan.upperBound...].dropLast()
let name = string[...rangeOfLessThan.lowerBound].trimmingCharacters(in: CharacterSet(charactersIn: "\" <"))
return (name: String(name), email: String(email))
} else {
return (name:"", email:string)
}
}
let string = "\"Some Guy\" <mailer-daemon@googlemail.com>"
let extractedString = extractNameAndMail(in: string)
强制执行单维视角
pandas.Series