【发布时间】:2017-04-05 09:24:16
【问题描述】:
我不明白为什么 pandas 数据框将我的列中的值四舍五入,我将其他两列的值相除。我希望新列中的数字带有两位小数,但值是四舍五入的。我检查了列的 dtypes,两者都是“float64”。
import pandas as pd
import numpy as np
# CURRENT DIRECTORY
cd = os.path.dirname(os.getcwd())
# concatenate csv files
dfList = []
for root, dirs, files in os.walk(cd):
for fname in files:
if re.match("output_contigs_SCMgenes.csv", fname):
frame = pd.read_csv(os.path.join(root, fname))
dfList.append(frame)
df = pd.concat(dfList)
#replace nan in SCM column with 0
df['SCM'].fillna(0, inplace=True)
#add column with genes/SCM
df['genes/SCM'] = df['genes']/df['SCM']
输出如下:
genome contig genes SCM genes/SCM
0 20900 48 1 0 inf
1 20900 37 130 103 1
2 20900 35 1 1 1
3 20900 1 79 66 1
4 20900 66 5 3 2
但我希望我的最后一列不包含四舍五入的值,而是包含至少 2 个小数的值。
【问题讨论】:
-
我无法复制它。你的 Python、Pandas 和 Numpy 版本是什么?
-
不,遗憾的是输出仍然相同
-
我正在使用 Anaconda3
-
恭喜获得 15 次代表!!!现在您可以投票了,请随时为您认为有用的答案投票。