我得到了各种格式的电话号码清单:
df = pd.DataFrame(
{'phone': ['0123/12345', '0123-23456', '0123/4455-10', '0123-4455-22'],
'name': ['A-1', 'B-1', 'C/3', 'D/7']})
name phone
0 A-1 0123/12345
1 B-1 0123-23456
2 C/3 0123/4455-10
3 D/7 0123-4455-22
Run Code Online (Sandbox Code Playgroud)
我想要的格式是#0和#2行.
当我专注于#1时,我尝试了以下方法:
df.loc[(df.phone.str.count('-')==1) &
(df.phone.str.count('/')==0)].apply(lambda x: x.str.replace('-', '/'))
Run Code Online (Sandbox Code Playgroud)
这就是数字的诀窍,但不幸的是在名称列上:
name phone
1 B/1 0123/23456
Run Code Online (Sandbox Code Playgroud)
但是不能更改名称列.
所以我有两个问题:
我有一个方法,应该删除字符串中的重复字符,并用i字符替换j字符,但替换不起作用!! 我的代码中有没有错误的陈述?
public string filter(string key)
{
string answer = "";
string keyEdit = key;
bool found = keyEdit.Contains('j');
if (found)
{
keyEdit.Replace('j', 'i'); // Replace j character by i character
}
answer = new string(keyEdit.Distinct().ToArray()); // Removing duplicate characters
return answer;
}
Run Code Online (Sandbox Code Playgroud) [UPDATED QUESTION]
I've got a variable $CHANGED which stores the output of a subversion command like this: CHANGED="$(svnlook changed -r $REV $REPOS)".
Executing svnlook changed -r $REV $REPOS will output the following to the command line:
A /path/to/file
A /path/to/file2
A /path/to/file3
Run Code Online (Sandbox Code Playgroud)
However, I need to store the output formatted as shown below in a variable $FILES:
A /path/to/file<br />A /path/to/file2<br />A /path/to/file3<br />
Run Code Online (Sandbox Code Playgroud)
I need this for using $FILES in a command which generates an email massage …
我想用*符号替换前3个字符和最后3个字符而不使用任何内置函数.
$string = array("johndoee","shawnmarsh","peterparker","johndoee","shawnmarsh","peterparker");
Run Code Online (Sandbox Code Playgroud)
你能指导我吗?有没有办法做到这一点?
我在思考某些事情时遇到了麻烦,并且会喜欢一些指导.
我有一个数据框,其中包含具有应上载某些文件的事件日期的列,以及包含这些事件名称的列.因此事件可以是X,Y,Z,文件可以是1,2,3.
并非所有文件都需要在所有事件中上传,即如果是事件X,则需要上传文件1,2和3,但如果是事件Y,则只需要上传文件3.日期列中包含日期,或者为空白.
我想要做的是,对于不需要的事件的所有文件,用"不需要"替换空白.
初始:
File1 File2 File3
X Aug 1 Sept 1
X Aug 3 Aug 4 Sept 9
Y Sept 10
Z Aug 12
X Aug 13 Aug 15
Z Aug 1
Run Code Online (Sandbox Code Playgroud)
目标
File1 File2 File3
X Aug 1 Sept 1
X Aug 3 Aug 4 Sept 9
Y NN NN Sept 10
Z Aug 12 NN NN
X Aug 13 Aug 15
Z Aug 1 NN NN
Run Code Online (Sandbox Code Playgroud)
换句话说,对于因为不期望文件而应该为空的空白,将该值替换为"Not Needed",同时保留其他空白.
我试过用.replace(),. apply()和函数做这个,我没有任何成功.
下面的代码有点工作,但它不仅适用于匹配,但即使没有匹配.
Fill in descriptive text for …Run Code Online (Sandbox Code Playgroud) 我有一个字符串:
str = 'Mr[5]'
Run Code Online (Sandbox Code Playgroud)
我想切换的位置Mr,并5在str,并得到这样的结果:
result = '[5]Mr'
Run Code Online (Sandbox Code Playgroud)
我怎么能在R中这样做?
在java中我只需要用一个单词替换一个数字,如果它不在"+"之前.例:
- match1
- match+1
Run Code Online (Sandbox Code Playgroud)
应该成为:
matchone
match+1 (no modify)
Run Code Online (Sandbox Code Playgroud)
我试过了
>>>name = name.replaceAll("([^+])1", "one");
matcone //required "matchone"
Run Code Online (Sandbox Code Playgroud)
但它没有用.有什么建议?
谢谢
我需要过滤变量的内容,以将所有具有匹配字符串的行从SubnetExceptions.txt文件中排除,作为过滤器,就像一条grep -v命令一样。
$Value为了获得所需的格式,该变量经过了很多处理。
该代码的工作部分如下:
$Value=netsh dhcp server show mibinfo | findstr "Subnet Addresses"
$Value=$Value -replace "Subnet","% `n Subnet"
$Value=$Value -replace "No. of Addresses in use","AddressesInUse"
$Value=$Value -replace "No. of free Addresses","AddressesFree"
$Value=$Value -replace '^.|.$', ' '
$Value=$Value -replace ' ', ""
$Value=$Value -replace ' ', " "
$Value= -join $Value
$Value=$Value -replace '\n', ''
$Value=$Value -replace "% ", "`n"
$Value=$Value -replace ' = ', '='
Run Code Online (Sandbox Code Playgroud)
ps1的前11行$Value从以下命令处理该命令的输出():
子网= 10.1.8.0。
正在使用的地址数= 11。
免费地址数= 18。
子网= … 我试图替换字符串中的单词但是我想在函数中找到单词并将其替换为带有确切长度的星号的单词?
这是可能的还是我需要以其他方式做到这一点?
$text = "Hello world, its 2018";
$words = ['world', 'its'];
echo str_replace($words, str_repeat("*", count(FOUND) ), $text);
Run Code Online (Sandbox Code Playgroud) 我有两个长度不等的词典,例如:
people = {"john" : "carpenter", "jill": "locksmith", "bob":"carpenter", "jane": "pilot", "dan": "locksmith"}
jobcode = {"carpenter": 1, "locksmith": 2, "pilot": 3}
Run Code Online (Sandbox Code Playgroud)
就是我想要做的是替换值people与jobcode值.所以你最终得到:n
people = {"john": 1, "jill": 2, "bob": 1, "jane": 3, "dan":2}
Run Code Online (Sandbox Code Playgroud)
我很乐意再作新的dict封装这个新的数据很好,但到目前为止,我想我已经最接近的是这个 ...我想...
任何帮助将不胜感激.
replace ×10
string ×4
python ×3
pandas ×2
php ×2
apply ×1
arrays ×1
bash ×1
c# ×1
dictionary ×1
java ×1
line-breaks ×1
powershell ×1
python-3.x ×1
r ×1
regex ×1
scripting ×1
str-replace ×1
updates ×1