
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Replace Odd Index Positions with Random Uppercase Vowels in Python
Input − Assume, you have a Series,
0 1 1 2 2 3 3 4 4 5
Output −
And, the result after replacing odd index with uppercase vowels as follows −
0 1 1 A 2 3 3 U 4 5
Solution
Define a Series.
Define uppercase alphabets
Create lambda filter method and replace vowels in all index positions. It is defined below
vowels = re.findall(r'[AEIOU]',chars) result = pd.Series(filter(lambda x: r.choice(vowels) if(x%2!=0),l)data)
Example
import pandas as pd import random as r l = [1,2,3,4,5] data = pd.Series(l) print(“Given series:\n”, data) vowels = list("AEIOU") for i,j in data.items(): if(i%2!=0): data[i]="".join(r.choice(vowels)) print("modified series:-\n",data)
Output
Given series: 0 1 1 2 2 3 3 4 4 5 dtype: int64 modified series:- 0 1 1 O 2 3 3 E 4 5 dtype: object
Advertisements