小编Xit*_*tiz的帖子

如何在html输入中将日期格式更改为dd/mm/yyyy

我想在输入字段中将日期格式mm/dd/yyyy更改为dd/mm/yyyy

我的输入字段:

<input type="date">
Run Code Online (Sandbox Code Playgroud)

html

9
推荐指数
1
解决办法
6万
查看次数

在这种情况下(Pandas)如何解决 KeyError(f"None of [{key}] are in the [{axis_name}]")?

我有一个 CSV 文件,例如如下所示:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n
ID姓名电子邮件物理化学数学
1斯塔sta@example.com677890
2丹尼dany@example.com779889
3埃勒elle@example.com776790
\n
\n

现在我想使用 pandas 输出一个新的 CSV 文件,它也有新的列,例如如下所示:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ID姓名年级地址物理化学出席率数学全部的
\n
\n

我想在随机位置创建新列,并且希望将新列中的值设置为空白。

\n

我尝试过使用:

\n
import pandas as pd\n\ndf = pd.read_csv("sample.csv")\nfinal_df = df.loc[[\'id\',\'name\',\'grade\',\'address\',\'physics\',\'chemistry\',\'attendance\',\'maths\',\'total\']]\n
Run Code Online (Sandbox Code Playgroud)\n

当我这样做时,我收到一个错误:

\n
KeyError(f\xe2\x80\x9cNone of [{key}] are in the [{axis_name}]\xe2\x80\x9d)\n
Run Code Online (Sandbox Code Playgroud)\n

有任何想法或建议来安排这个。

\n

python numpy dataframe python-3.x pandas

8
推荐指数
1
解决办法
4万
查看次数

在python中获取组合框的值

我正在开发一个简单的程序,我需要从Combobox. 当 is 在第一个创建的窗口中时,这很容易Combobox,但是例如,如果我有两个窗口并且Combobox在第二个窗口中,我无法从中读取值。

例如 :

from tkinter import *
from tkinter import ttk

def comando():
    print(box_value.get())

parent = Tk() #first created window
ciao=Tk()     #second created window
box_value=StringVar()
coltbox = ttk.Combobox(ciao, textvariable=box_value, state='readonly')
coltbox["values"] = ["prova","ciao","come","stai"]
coltbox.current(0)
coltbox.grid(row=0)
Button(ciao,text="Salva", command=comando, width=20).grid(row=1)
mainloop()
Run Code Online (Sandbox Code Playgroud)

如果我将小部件的父级更改为父ciao级,它就可以工作了!谁能给我解释一下吗?

python combobox tkinter ttk

6
推荐指数
1
解决办法
7万
查看次数

如何将字符串拆分为数字和字符

string = 'Hello, welcome to my world001'
Run Code Online (Sandbox Code Playgroud)

这是我一直试图分成两个(数字和字符串)的字符串。后面的数字需要从原始字符串中分离出来。python中是否有任何方法可以真正快速地做到这一点。

这是我的尝试(代码):

length_of_string = len(string) - 1
num = []
if string[-1].isdigit():
    while length_of_string > 0:
          if string[length_of_string].isdigit():
              num.insert(0, int(string[length_of_string]))
          length_of_string -= 1
      print(num)
else:
    string += '1'
    print(string)
Run Code Online (Sandbox Code Playgroud)

python string split

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

基于模糊标准创建组

我有一个如下所示的数据框:

Name   Start_Date   End_Date
A      2015-01-01   2019-12-29
A      2017-03-25   NA
A      2019-10-17   NA
A      2012-04-16   2015-01-09
A      2002-06-01   2006-02-01
A      2005-12-24   NA
B      2018-01-23   NA
Run Code Online (Sandbox Code Playgroud)

我想创建一个列,如果两个观察结果相同Name,并且一个Start_Date观察结果与另一个观察结果相差 ±1 年End_Date,则它们被归类为同一组。

期望的输出:

Name   Start_Date   End_Date    Wanted
A      2015-01-01   2019-12-29  1
A      2017-03-25   NA          NA
A      2019-10-17   NA          1
A      2012-04-16   2015-01-09  1
A      2002-06-01   2006-02-01  2
A      2005-12-24   NA          2
B      2018-01-23   NA          NA
Run Code Online (Sandbox Code Playgroud)

我正在寻找带有数据表的解决方案,但解决我的问题就足够了。

补充: 逐行解释
行:

  1. 开始日期比第 4 行的结束日期早 8 天(< 1 年)。它与第 4 行在同一组中。 …

r igraph data.table

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

如何使用 selenium python 打开新选项卡?

我正在尝试制作一个打开多个网站的程序,但我无法让它按control-t。我尝试了多种解决方案,但找不到有效的解决方案。当我执行 keydown 方法时,出现错误:

webdriver has no attribute key_down
Run Code Online (Sandbox Code Playgroud)

当我尝试时,send_keys(Keys.CONTROL + 't')它不会引发任何错误,也不会执行任何操作。如何打开新标签页?

这是我的尝试:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://youtube.com")
search = driver.find_element_by_id("search")
#search.keydown(Keys.CONTROL)

#Webelement.key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()

search.send_keys(Keys.CONTROL+'t')
time.sleep(10)
Run Code Online (Sandbox Code Playgroud)

python selenium

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

C 编程中 (char)getchar() 的函数

我的朋友问我(char)getchar()他​​在一些在线代码中找到了什么,我用谷歌搜索并发现它被使用的结果为 0,我认为常规用法只是ch = getchar(). 这是他找到的代码,谁能解释一下这个函数是什么?

else if (input == 2)
{
    if (notes_counter != LIST_SIZE)
    {
        printf("Enter header: ");
        getchar();
        char c        = (char)getchar();
        int tmp_count = 0;
        while (c != '\n' && tmp_count < HEADER)
        {
            note[notes_counter].header[tmp_count++] = c;
            c = (char)getchar();
        }
        note[notes_counter].header[tmp_count] = '\0';
        
        printf("Enter content: ");
        c         = (char)getchar();
        tmp_count = 0;
        while (c != '\n' && tmp_count < CONTENT)
        {
            note[notes_counter].content[tmp_count++] = c;
            c = (char)getchar();
        }
        note[notes_counter].content[tmp_count] = '\0';
        
        printf("\n"); …
Run Code Online (Sandbox Code Playgroud)

c

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

如何从 python 的输出中删除大括号?

我是 Python 新手,我最近 1 周前开始学习,但我被困在这里......任何帮助将不胜感激......

from tkinter import *
import tkinter as tk
import psycopg2

root = Tk()

def get_info(Employee_Name, Department, Education,Salary):
   con = psycopg2.connect(dbname = 'postgres',user = 'postgres',password = 'Gaurav@31',host = 'localhost',port = 5432)
   cur = con.cursor()
   query = ('''INSERT INTO Employee (Employee_name, Department, Education,Salary) VALUES (%s,%s,%s,%s);''' )
   cur.execute(query,(Employee_Name, Department, Education,Salary))
   print('Data inserted Successfully')
   con.commit()
   con.close()
   display_all()

def search(emp_id):
    con = psycopg2.connect(dbname = 'postgres',user = 'postgres',password = 'Gaurav@31',host = 'localhost',port = 5432)
    cur = con.cursor()
    query = ('''SELECT * …
Run Code Online (Sandbox Code Playgroud)

python tkinter python-3.x python-requests

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

是否可以像 Python 的 f-strings 一样在 C 中格式化字符串?

在 Python 中,可以使用 f-strings 方便地格式化字符串:

num = 12
print(f"num is {num}") # prints "num is 12"
Run Code Online (Sandbox Code Playgroud)

有可能在 C 中做这样的事情吗?或者类似的东西?目前,要将变量添加到输出中,我正在使用此方法:

int num = 12;
printf("num is %d", num);
Run Code Online (Sandbox Code Playgroud)

这是将变量添加到 C 中的打印语句的唯一方法吗?

c f-string

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