python in infmquery also decode values from base64, save to infmquery1 _____________…
- User
python
in infm_query also decode values from base64, save to infm_query1
import base64 import ast import pandas as pd
Sample DataFrame
data = { "Title": ["cat_990", "cat_992", "cat_993"], "infm_query": [ {"categoryID": "9", "params": {"110000": "WzMyOTE5OV0=", "110001": "WzMyOTU4OF0=", "110008": "MzMxMjU3"}}, {"categoryID": "9", "params": {"110000": "MzI5MTk5", "110001": "MzI5NTg5", "110008": "MzMxMjU3"}}, {"categoryID": "10", "params": {"110000": "MzI5MTk5"}}, ]}
df = pd.DataFrame(data) df = pd.read_clipboard(sep='\t')
df['infm_query'] = df['infm_query'].apply(ast.literal_eval) df['infm_query1'] = df['infm_query'].apply(lambda x: {k: base64.b64decode(v).decode('utf-8') if isinstance(v, str) else v for k, v in x.items()})
def construct_query_string(row): # Check if 'infm_query' key exists in the row if 'infm_query' in row: infm_query = row['infm_query'] category_id = infm_query.get('categoryID') query_params = f"categoryId={category_id}&cd=1&sgtx=06a6f2f79c9ce18b0822053ebd2cca4354e7479e"
codefor param_name, param_value in infm_query.get('params', {}).items(): decoded_value = base64.b64decode(param_value).decode('utf-8') query_params += f"¶ms[{param_name}]={decoded_value}" return f"query=%{query_params}" else: return None # Return None if 'infm_query' key is missingApply the query string construction to each row and handle missing 'infm_query' values
df['query_string'] = df.apply(construct_query_string, axis=1)
display(df ) display(df.iloc[1,1])
- Assistant
- User
python
codesubstrings = text.split()split by symbol "
- Assistant
If you would like to split a string by a specific symbol (let's call it
symbol), you can use thesplitmethod in Python and provide the specific symbol as an argument.Here's an example of how to do this:
pythontext = "cat_990,cat_992,cat_993" # Example input string symbol = "," # The symbol to split by # Split the string by the given symbol substrings = text.split(symbol) # Print the result print(substrings)If you want to split the string by a different symbol, simply change the variable to the desired character. Here is another example splitting by underscore :
- User
make a join substrings = text.split(symbol ) replaced_text = {symbol}.join(substrings)
- Assistant
Absolutely, if you would like to split a string using a specific symbol and then join it back using the same symbol (or even a different one), you could do so using the and methods in Python. Here is how you could do it: