Python Float到Int转换错误

时间:2015-12-10 16:57:26

标签: python python-2.7 integer

我对python很陌生。我的目标是将float更改为int。浮子是一系列。没有Nans。我查看了很多帖子,包括:Pandas: change data type of Series to String

我尝试了几种不同类型的语法:

```comp.month.apply(int)``` 

此处出现的错误。

```TypeError Traceback (most recent call last) <ipython-input-190-690a8228abec> in <module>()
----> 1 comp.month.apply(int)
/Users/halliebregman/anaconda/lib/python2.7/site-packages/pandas/core/series.pyc in apply(self, func, convert_dtype, args, **kwds)
2058             values = lib.map_infer(values, lib.Timestamp)
----> 2060         mapped = lib.map_infer(values, f, convert=convert_dtype)
2061         if len(mapped) and isinstance(mapped[0], Series):
2062             from pandas.core.frame import DataFrame
pandas/src/inference.pyx in pandas.lib.map_infer (pandas/lib.c:58435)()
TypeError: 'file' object is not callable```

还有:

```with open ("ints.csv", "w") as ints:
    for i in range(len(comp)):
        months = int(comp['month'][i])
        days = int(comp['day'][i])
        print months, days
        ints.write('{} {} \n'.format(months, days))```

后面跟着这个错误:

```TypeError Traceback (most recent call last) <ipython-input-191-0d6fe0a99830> in <module>()  
1 with open ("ints.csv", "w") as ints:
2     for i in range(len(comp)):
----> 3         months = int(comp['month'][i])
4         days = int(comp['day'][i])
5         print months, days
TypeError: 'file' object is not callable```

我在这里缺少什么?看起来这应该很简单:/

谢谢!

0 个答案:

没有答案
相关问题