0
value_temp = p.split(';')
value = round(float(value_temp[2]),5)
for i in range(24):
    df_1.loc[i] = [1,date[0],value[i]]
print(df_1)

我拆分了一个字符串。我想要做的是从字符串中提取值并将其更改为浮点数,然后将其放入 DataFrame 中。但是我将值放入 DataFrame 时出错。

4

1 回答 1

0

Is this what you're trying to do?

p = "1;2;3;4;5;6"
p.split(';')
['1', '2', '3', '4', '5', '6']

n = [float(x) for x in p.split(";")]
df = pd.DataFrame({'a':['a','b','c','d','e','f']})
df['num'] = n
于 2019-03-12T03:54:07.807 回答