일련의 반올림 dataframe 2 곳으로팬더 내가 같은 팬더 시리즈가
23.340000
24.350000
......
내가 float로 변환하고 싶습니다를 다음 라운드
tempDF['A'] = round(dfOld.cl.astype(float),2)
출력 같아야
23.34
24.35
.....
가장 좋은 방법은 무엇입니까?
일련의 반올림 dataframe 2 곳으로팬더 내가 같은 팬더 시리즈가
23.340000
24.350000
......
내가 float로 변환하고 싶습니다를 다음 라운드
tempDF['A'] = round(dfOld.cl.astype(float),2)
출력 같아야
23.34
24.35
.....
가장 좋은 방법은 무엇입니까?
당신이 달성하기 pandas.Series.round 기능을 사용할 수 있습니다 : 당신은 당신이 제공 한 코드를 실행할 때 무엇을 어떻게해야합니까
In [1]: import pandas as pd
In [2]: dfOld = pd.DataFrame({'cl': ['0.014', '0.015', '0.016']})
dfOld.cl.apply(type).value_counts() # prove that the values are strings
Out[2]:
<type 'str'> 3
dtype: int64
In [3]:
dfOld.cl.astype(float).round(decimals=2)
Out[3]:
0 0.01
1 0.02
2 0.02
Name: cl, dtype: float64
덧붙여 말하면,'jupyter-notebook'을 사용하고 있다면'df.cl.
를, "tempDF [ 'A'] = 라운드 (dfOld.cl.astype (플로트) , 2) "? 해당 코드가 올바른 것 같습니다. –