次のことを試すと:
# Define the mapping
def my_float_to_string(f):
return "{:g}".format(f)
# This returns numpy.float64
type(my_xls['Subject'][0])
my_df['foo'] = my_df['foo'].map(float_to_string)
私は得る:
ValueError: Unkonwn format code 'g'for object of type 'str'
ただし、次の場合はうまく機能します
test = my_float_to_string(5.0)
print test
'5'
関数を要素ごとに Series
オブジェクトに適用できないのはなぜですか?
また、なぜ DataFrame と Series は要素ごとの操作に対して異なるメソッド名を持っているのですか (つまりmap
、Seriesapplymap
と DataFrame の場合)。