2

This is pretty direct, I was trying to replicate the example used in Swifter page https://github.com/jmcarpenter2/swifter. However, I keep getting the error AttributeError: 'Series' object has no attribute 'swifter'. What's up with that?

Update - The example I tried:

import pandas as pd
import swifter 

df = pd.DataFrame({'x': [1, 2, 3, 4], 'y': [5, 6, 7, 8]})

# runs on single core
df['x2'] = df['x'].apply(lambda x: x**2)
# runs on multiple cores
df['x2'] = df['x'].swifter.apply(lambda x: x**2)

# use swifter apply on whole dataframe
df['agg'] = df.swifter.apply(lambda x: x.sum() - x.min())

# use swifter apply on specific columns
df['outCol'] = df[['inCol1', 'inCol2']].swifter.apply(my_func)
df['outCol'] = df[['inCol1', 'inCol2', 'inCol3']].swifter.apply(my_func,
         positional_arg, keyword_arg=keyword_argval)
4

0 回答 0