I want to create a new list merging the elements of a previous list plus the values of a specific column of one data frame. See the example below.
The list I already have:
JavaScript
x
2
1
variables = ['Price_x_x', 'Mkt Cap_x', '24h Volume_x','Contributors_x', 'Commits in Last 4 Weeks_x','Reddit Subscribers_x', 'FB Likes_x','Market Cap Dominance']
2
The column:
JavaScript
1
13
13
1
0 BTC
2
1 ETH
3
2 BNB
4
3 USDT
5
4 DOT
6
7
995 CPC
8
996 BLK
9
997 ROUTE
10
998 CNN
11
999 BULL
12
Name: COIN, Length: 1000, dtype: object
13
The desired output:
JavaScript
1
3
1
['BTC_Price_x_x', 'BTC_Mkt Cap_x','BTC_24h Volume_x', ,'BULL_FB Likes_x','BULL_Market Cap Dominance']
2
3
Advertisement
Answer
IIUC, just loop over them:
JavaScript
1
5
1
result = []
2
for ticker in df['desired_col'].unique():
3
for variable in variables:
4
result.append(f"{ticker}_{variable}")
5