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)

I split a string. What I want to do is extract the values from string and change it to float, and then put it into DataFrame. But I'm getting error from putting values in a DataFrame.

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
김경수
  • 1
  • 1
  • Where does this error occur in your code? Please provide sample data to reproduce the problem, or at least the full traceback – ALollz Mar 12 '19 at 03:34
  • what are you doing with the for loop? It looks like value is a single float. Why are you iterating through a range of 24 and taking each number in the float? Can you provide us with what p looks like? – Matt W. Mar 12 '19 at 03:52

1 Answers1

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
Matt W.
  • 3,692
  • 2
  • 23
  • 46