I'm sorry for the introductory question, but I would appreciate your help.
I'm using Pandas to aggregate downloaded CSV files like attached photos.
In the place colored in yellow, there is a notation of "number + X" in parentheses after the number, so the average or total group by method cannot be used for each name.
When I converted it to Nan with the replace function and handled it, the numerical value I wanted to aggregate before the parentheses was also converted to Nan, so I asked a question without thinking of a good method with a conditional statement that ignores the value in parentheses.
I would appreciate it if you could teach me.
Answer # 1
It is better to apply a function that removes the "(~)" part with apply instead of replace. If you convert to int at the same time, the processing can be done at once.
For me, use re.sub () to delete it.
Answer # 2
How about modifying the string of data in the dataframe with apply?
df ["Year H1cm total"] = df ["Year H1cm total"]. Apply (lambda x: re.sub (r "\ (. + \)", "", X))
You should now be able to remove the "(~)" part.
Also, as it is, it is still a character string, so if you want to convert it to a numerical value at the same time,
df ["Year H1cm total"] = df ["Year H1cm total"]. Apply (lambda x: int (re.sub (r "\ (. + \)", "", X)))
I think you should add an int like this.
Also, when you look at the image, the parentheses appear to be full-width, so in that case you must also specify the parentheses in the corresponding expression.
- parallel processing using python multiprocessingpool and multiprocessingqueue does not work well
- python 3x - processing to jump to the link destination using chrome driver in python
- python - websocket processing using asyncio
- python 3x - i want to concatenate data using pandas merge, but it doesn't work
- python - tkinter parallel processing
- eliminating pandas install and import in python pyenv export ldflags
- python 3x - how to rename a folder created using jupyternotebook
- python - merge after pandas pivot
- about processing to exclude the character string group specified from list in python
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - error in image binarization using cv2adaptivethreshold function
- processing python dat files
- python - speech processing typeerror:'int' object is not subscriptable
- about batch change of file name using python
- python - image recognition using cnn keras multiple inputs
- python - i want to separate by a specific word using the split function
- about external libraries when using multiple versions of python
- python - shuffle a few lines of pandas for weekdays and holidays
- i want to adjust the execution result using the while statement in python as expected
- python : Gender identification by name
- python : The function issues an error due to the immaculate retirement, Hova with them all right
- python : How to rescue from the site specific data?
- Python -How to create a 2D array of DataFrame?
- python : Finding a double and removal with the smallest value
- python : Typeerror: '(Slice (None, None, None), 0)' IS An Invalid Key when building a definition coefficient charts
- python : How to create other columns with binary signs by value from the speaker?
- python : How to remove speakers in a dataframe mask
- python : Pandas Apply a regular expression to the column and how to make a regular expression
- Merge in Python: does not work with different types of data