我有一个元素列表,但是应该使用,-分隔符将这些元素分隔为更多元素。
[[{'col1': '81627', 'picture_date': '2018-03-26'},
{'col1': '82034', 'picture_date': '2018-03-28'},
{'col1': '81625', 'picture_date': '2018-03-26'},
{'col1': '81626', 'picture_date': '2018-03-26'}]]
这是一个列表项列表[1],但应分为4个列表项。什么是有效的方法?
答案 0 :(得分:1)
您可以尝试拼合列表:
df = pd.DataFrame([l for d in data for l in d])
输出:
# col1 picture_date
# 0 81627 2018-03-26
# 1 82034 2018-03-28
# 2 81625 2018-03-26
# 3 81626 2018-03-26
修改
要能够对数据执行一些计算,您需要使用相应的 type 转换列。您可以使用dtypes
types
print(df.dtypes)
# col1 object
# picture_date object
# dtype: object
pd.to_numeric
。pd.to_datetime
df["col1"] = pd.to_numeric(df["col1"])
df["picture_date"] = pd.to_datetime(df["picture_date"])
print(df.dtypes)
# col1 int64
# picture_date datetime64[ns]
# dtype: object
答案 1 :(得分:0)
我认为这对您有用
dependencies {
compile 'org.apache.maven.plugins:maven-surefire-plugin:2.21.0'
}
test {
ignoreFailures = true
include '**/RunCucumberIT.java'
//option doesn't works
//options {
//parallel = "methods"
//forkCount = 4
}
}
答案 2 :(得分:0)
我建议使用列表理解功能(对于我们还不认识大熊猫的那些人):
your_list = [[
{'col1': '81627', 'picture_date': '2018-03-26'},
{'col1': '82034', 'picture_date': '2018-03-28'},
{'col1': '81625', 'picture_date': '2018-03-26'},
{'col1': '81626', 'picture_date': '2018-03-26'},
]]
what_you_want = [item for sub_list in your_list for item in sub_list]
print(what_you_want)
输出:
[{'col1': '81627', 'picture_date': '2018-03-26'}, {'col1': '82034', 'picture_date': '2018-03-28'}, {'col1': '81625', 'picture_date': '2018-03-26'}, {'col1': '81626', 'picture_date': '2018-03-26'}]