小编che*_*omo的帖子

Python,我错误的删除字符串元音的功能?

我正在关注codecademy教程,问题是"定义一个名为anti_vowel的函数,它接受一个字符串,文本作为输入,并返回删除了所有元音的文本.

例如:anti_vowel("嘿你!")应该返回"Hy Y!"."

代码:

def anti_vowel(text):
    textlist = list(text)
    print textlist
    for k in textlist:
        if k in"aeiouAEIOU":
            print k
            textlist.remove(k)
    return "".join(textlist)
Run Code Online (Sandbox Code Playgroud)

错误是"哎呀,再试一次.你的功能在anti_vowel上失败了("嘿看单词!").当它应该返回"Hy lk Wrds!"时,它会返回"Hy lk Words!".
我不知道为什么还有额外的"o"呢?谁能告诉我导致错误的原因是什么?谢谢!

python

3
推荐指数
1
解决办法
757
查看次数

如何使用包含if-else结构的函数到每个列使用R.

数据框sg如下:

 v1 v2 v3 
 A  B  C  
 B  A  B  
 C  A  A  
Run Code Online (Sandbox Code Playgroud)

我用了一个功能

definition <- funciton(x){
  if (x =='A') definition <- paste(x, ": MINIMUM_RED")   
  else if (x =='B') definition <- paste(x, ": PASSIVE_RED")   ## Passive red (no green demand during red)
  else if (x =='C') definition <- paste(x, ": RED_REQUEST")   ## During red the group has a green demand
  else if (x =='D') definition <- paste(x, ": RED_PRIORITY")  
  else if (x =='E') definition <- paste(x, ": RED_PRIVILEGE")  ## During …
Run Code Online (Sandbox Code Playgroud)

if-statement r apply lapply dataframe

2
推荐指数
1
解决办法
345
查看次数

如何使用R添加毫秒到日期类型?

我的数据框状态如下:

   sg           date_time      tick_count
1      4 2014-07-24 11:02:02          0
2      4 2014-07-24 11:02:02          6
3      4 2014-07-24 11:02:02         19
4      4 2014-07-24 11:02:02         11
5      4 2014-07-24 11:02:02         15
6      4 2014-07-24 11:02:02         17
7      4 2014-07-24 11:02:02         29
8      4 2014-07-24 11:02:02         24
9      4 2014-07-24 11:02:02         38
10     < 2014-07-24 11:02:02         30
11     < 2014-07-24 11:02:02         34
12     < 2014-07-24 11:02:02         40
13     < 2014-07-24 11:02:02         41
14     < 2014-07-24 11:02:02         42
15     < 2014-07-24 11:02:02         47
Run Code Online (Sandbox Code Playgroud)

列tick_count的单位是100毫秒.我需要在date_time上添加tick_count时间来创建一个新的时间列. …

datetime r milliseconds unix-timestamp

1
推荐指数
1
解决办法
1012
查看次数

如何使用jdbc将数据从postgresql导出到.csv文件?

我想按日期在表中导出数据,所以我用jdbc编写了一个java程序.

  public void exportData(Connection conn,String filename) {

        Statement stmt;
        String query;
        try {
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_UPDATABLE); 

            SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
            Date startDate = dateFormat.parse("2014-08-21 00:00:00");
            Date endDate = dateFormat.parse("2014-08-22 00:00:00");

            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(startDate);

            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(endDate);

            Calendar thisDayCalendar = startCalendar;

            while(!thisDayCalendar.after(endCalendar)){
                Date thisDayDate = thisDayCalendar.getTime();
                thisDayCalendar.add(Calendar.DATE, 1);
                Date nextDayDate = thisDayCalendar.getTime();

                String thisDayString = dateFormat.format(thisDayDate);
                String nextDayString = dateFormat.format(nextDayDate);

                SimpleDateFormat dateFormat1 = new SimpleDateFormat ("yyyy-MM-dd");
                String fileDateString = dateFormat1.format(thisDayDate);

                //For comma separated …
Run Code Online (Sandbox Code Playgroud)

java postgresql jdbc

1
推荐指数
1
解决办法
5073
查看次数

如何将每两列合并为一列,将列数合并为一半

数据框df:

  0 1 2 3 4 A B C D E 
1 0 1 1 0 0 a b d s e     
2 0 0 1 0 0 a w d d e     
3 0 0 1 1 0 a c w d e
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以通过合并每两列对应的索引号和字母将数据帧转换为新的数据帧?

  0(A) 1(B) 2(C) 3(D) 4(E) 
1 0(a) 1(b) 1(d) 0(s) 0(e)     
2 0(a) 0(w) 1(d) 0(d) 0(e)   
3 0(a) 0(c) 1(w) 1(d) 0(e) 
Run Code Online (Sandbox Code Playgroud)

merge r dataframe

0
推荐指数
1
解决办法
62
查看次数