Extract nested column using another column value
APIs and document databases sometimes return nested JSON objects and you’re trying to promote some of those nested keys into column headers but loading the data into pandas gives you something like this:
df = pd.DataFrame.from_records(results["issues"], columns = ["key", "fields"])
One possible way is to convert the struct type column to map type:, Questions ,Science Fiction & Fantasy, Podcast 377: You don’t need a math PhD to play Dwarf Fortress, just to code it
import pyspark.sql.functions as F df2 = df.withColumn( 'setting_value', F.from_json(F.to_json('data'), 'map<string,string>')[F.col('setting_name')] )
Other "value-using" answers related to "Extract nested column using another column value"
- Got error from Text recognition using Tesseract in pycharm(Windows) [duplicate]
- The file with extension .txt doesn't work in Visual Studio Text Editor
- Python Function Error with Deep LS recursion generator
- Feature engineer a binary variable from a numerical variable
- AttributeError: 'BotClient' object has no attribute 'loop' with declaring an instance
- Map projections using Python Image Library instead of Matplotlib, and then warping the image to another projection?
- How to update (draw) a widget and only this widget in GTK
- Python / Dash : Multiple graphs inside a single subplot of the the figure
- UFuncTypeError: ufunc 'matmul' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32') - Streamlit
- Numpy Multi-stage Container Build — Alpine
- Error AttributeError: 'str' object has no attribute 'year' when querying a model
- How to implement simple tkinter GUI app with a single input box?
- Can I transfer every thing in the string to int and keep commas
- Discrepancy between a program in Python and C++
- Override class methods (e.g. __setattr__) after __init__()
- Command repeats when it should only work on everh other time through for loop - PYTHON
- How can I use Conda to install MySQLdb?
- Imputation of row values in Pandas DataFrame basis specific different column row values
- Cv2.imshow is not working even if my camera is on and I'm getting the frame printed?
- How to download .csv files from a list of given URLs using scrapy