[Python] Random data extraction / combination from DataFrame using random and pandas

[Self-introduction] I am a programming beginner for Qiita's first post. I'm doing a postcard reading corner with a voice distribution app that I'm doing as a hobby, and I started writing that it would be nice if there was a code that could output a unique radio name without permission.

[Environment] ・ Language: python 3.6.5 ・ OS: macOS Catalina 10.15.3 ・ IDE: VScode

[Overview] The word data saved in Excel is read by pandas DataFrame and two are randomly extracted. Here, two Excel files are prepared as the original data, but you can separate the sheets in the same file, or you can separate the columns in the same sheet. Since the combination of words depends on the manually entered character string, yesterday's automatic acquisition of other words was not implemented. (Therefore, it's a very simple code ...)

Data example |Word example 1| |:-----------------| |○○| |△△| |□□ But| |XX and|
Word example 2
aaa
bbb
ccc
ddd

[Details]

radioname_maker



#Import required libraries
#No need for os if you don't specify a working directory below
import random, os
import pandas as pd

#Specifying a working directory(If necessary)
path = "Enter a working directory if needed"
os.chdir(path)

#pandas.Load Excel into Dataframe
df_f = pd.read_excel("first_part.xlsx", header=0, na_values=0)
df_f_part = [f_p for f_p in df_f.iloc[:, 0]]

df_s = pd.read_excel("second_part.xlsx", header=0, na_values=0)
df_s_part = [s_p for s_p in df_s.iloc[:, 0]]

#Choose one word from each of the two Excels you read
first_choice = random.choice(df_f_part)
second_choice = random.choice(df_s_part)

#Join
radio_name = first_choice + second_choice

#Output to console
print(radio_name)

Example output result △△ ddd ○○ ccc etc...

Recommended Posts

[Python] Random data extraction / combination from DataFrame using random and pandas
Data analysis using python pandas
Convert from Pandas DataFrame to System.Data.DataTable using Python for .NET
Visualize plant activity from space using satellite data and Python
Hit treasure data from Python Pandas
Graph time series data in Python using pandas and matplotlib
[Python] What is pandas Series and DataFrame?
From Python to using MeCab (and CaboCha)
Python application: Pandas Part 4: DataFrame concatenation / combination
Create a dataframe from excel using pandas
[Python pandas] Create an empty DataFrame from an existing DataFrame
Python pandas: Search for DataFrame using regular expressions
[Python] How to read data from CIFAR-10 and CIFAR-100
[python] Create table from pandas DataFrame to postgres
Basic operation of Python Pandas Series and Dataframe (1)
Data analysis using Python 0
Data cleansing 2 Data cleansing using DataFrame
Data cleaning using Python
Python application: Pandas # 3: Dataframe
Process csv data with python (count processing using pandas)
Get files from Linux using paramiko and scp [Python]
Weighted random choice in python
Python attribute alias
Johnson method (python)
[Python] Semi-Lagrange method
Kernel Method with Python
Python installation method Windows
Random walk in Python
Simplex method (simplex method) in Python
Repeated weighted reduction method
Private method in python
[Python] Random data extraction / combination from DataFrame using random and pandas
Flatten using Python yield from
Create a decision tree from 0 with Python and understand it (3. Data analysis library Pandas edition)
Scraping desired data from website by linking Python and Excel
Predict gender from name using Gender API and Pykakasi in Python
Analyze stock prices using pandas data aggregation and group operations
[Python] Numpy reference, extraction, combination
Shoot time-lapse from a PC camera using Python and OpenCV
How to get followers and followers from python using the Mastodon API
[Python] How to add rows and columns to a table (pandas DataFrame)
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Collect product information and process data using Rakuten product search API [Python]
Practice of data analysis by Python and pandas (Tokyo COVID-19 data edition)
Conditional element extraction from data frame: R is% in%, Python is .isin ()
Python hand play (Pandas / DataFrame beginning)
[Python] Loading csv files using pandas
Python: Exclude tags from html data
[Python] Operation memo of pandas DataFrame
Using Rstan from Python with PypeR
Data visualization method using matplotlib (+ pandas) (5)
Get data from Quandl in Python
Authentication using tweepy-User authentication and application authentication (Python)
Python, yield, return, and sometimes yield from
Create a pandas Dataframe from a string.
Notes on using MeCab from Python
Precautions when using codecs and pandas
Read and use Python files from Python
About Python, from and import, as
Using Cloud Storage from Python3 (Introduction)
Hashing data in R and Python
Clustering and visualization using Python and CytoScape
Run Ansible from Python using API
Get data from Twitter using Tweepy
Precautions when using phantomjs from python
Access spreadsheets using OAuth 2.0 from Python
Data visualization method using matplotlib (+ pandas) (4)
Python application: Data cleansing # 2: Data cleansing with DataFrame
Try using Amazon DynamoDB from Python
Reading from text files and SQLite in Python (+ Pandas), R, Julia (+ DataFrames)
Easily exchange data between Python, R and Julia using the Feather format