仅将月份从“一月”更改为1,“二月”更改为2,“三月”更改为3…“十二月”更改为12

2024-09-29 23:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我让它工作了一次,但没有保存文件和丢失的代码。 请帮忙。你知道吗

 import pandas as pd
 import nltk

 df0.head(4)

#   X   Y   month   day FFMC    DMC DC
# 0 7   5   mar fri 86.2    26.2    94.3
# 1 7   4   oct tue 90.6    35.4    669.1


 monthdict={'jan':1,'feb':2'mar':3,'oct':10,'nov':11,'dec':12}

 def month2num(month):
    return monthdict[month]
 df0['month'] = df0['month'].apply(month2num)
 df0.head()

'注释' 我不是那么聪明,只是刚刚开始,所以请有人用英语解释解决方案。你知道吗

以下打印错误:

# KeyError                                  
# Traceback 
# (most recent call last)
# <ipython-input-48-566f3675aaed> in <module>()
#       def month2num(month):
#           return monthdict[month]
# ----> df0['month'] = df['month'].apply(month2num)
#       df0.head()

# 1 frames
# pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

# <ipython-input-48-566f3675aaed> in month2num(month)
#        
#        def month2num(month):
# ---->      return monthdict[month]
#        df0['month'] = df['month'].apply(month2num)
#        df0.head()

# KeyError: 'apr'

Tags: inimportpandasreturndefipythonheadoct
3条回答

即使使用remote debugging attached,在生产环境中运行应用服务器(Tomcat)也没有问题

更新

如果你想在应用程序中执行自定义代码,那么一个解决方案是编写一个类并编译它,将其存储在服务器上的某个位置,然后在应用程序中执行如下方法:

/**
 * This method:
 * <li>loads a class from the server file system
 * <li>does a lookup for the method to execute
 * <li>creates a new instance of the specified class
 * <li>executes the given method with the given arguments
 *     (which can be null if the method doesn't have arguments)
 * <li>returns the result of the invoked method
 * 
 * @param classUrlOnTheServer
 * @param className
 * @param methodNameToExecute
 * @param argumentsForTheMethod arguments that should be passed to
 *                              the method of the loaded class - can
 *                              be null.
 * @return returns the result of the invoked method
 * @throws ClassNotFoundException
 * @throws MalformedURLException
 * @throws SecurityException
 * @throws NoSuchMethodException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 */
public static Object loadAndExecuteCustomMethodFromALoadedClass(String classUrlOnTheServer,
                                                        String className,
                                                        String methodNameToExecute,
                                                        Object ... argumentsForTheMethod)
                                                                                        throws ClassNotFoundException,
                                                                                        MalformedURLException,
                                                                                        SecurityException,
                                                                                        NoSuchMethodException,
                                                                                        InstantiationException,
                                                                                        IllegalAccessException,
                                                                                        IllegalArgumentException,
                                                                                        InvocationTargetException {
   File file = new File(classUrlOnTheServer);
   URL url = file.toURI().toURL();  
   URL[] urls = new URL[] { url };
   ClassLoader cl = new URLClassLoader(urls);
   Class clazz = cl.loadClass(className);

   Method method = clazz.getDeclaredMethod(methodNameToExecute);
   Object instance = clazz.newInstance();
   Object result = method.invoke(instance, argumentsForTheMethod);
   return result;
}

我不明白这个问题,你只想连接到远程虚拟机吗?连接后,您可以执行任何您想要的操作,事件终止VM。 您必须在调试模式下启动VM:

-Xdebug-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

然后以Eclipse为例,创建一个新的远程应用程序概要文件。检查一下: http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html

我找到了实验解决方案:jsadebugd
然后你可以通过太阳来连接它。jvm。热点。杰迪。SAPIDAttachingConnector连接器

相关问题 更多 >

    热门问题