Get HTML table into pandas Dataframe, not list of dataframe objects
Tag : python , By : user186012
Date : March 29 2020, 07:55 AM
|
Extract Pattern in Pandas Dataframe
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am extracting a pattern from the column of the dataframe. Some has the Word 'Oscar' and some has the Word 'Oscars'. How to extract in the panda dataframe . Below is the extract line code. This gives error. , Is this what is needed? import pandas as pd
df = pd.DataFrame({'a': [1,2,3,4], 'b': ['is Oscar','asd','Oscars','not an Oscars q']})
df['c'] = ['Won 3 Oscars. Another 234 wins & 312 nominations.',
'Won 7 Oscars. Another 215 wins & 169 nominations.',
'Won 11 Oscar. Another 174 wins & 113 nominations.',
'Won 4 Oscars. Another 122 wins & 213 nominations.']
df['c'].str.extract('Won (\d+) Oscar[s]?', expand=True).fillna(0)
0
0 3
1 7
2 11
3 4
|
replace pandas DataFrame value pattern
Date : March 29 2020, 07:55 AM
With these it helps I think you need str.strip: df['order_number'] = df['order_number'].str.strip('"').astype(float)
df['order_number'] = df['order_number'].replace('"','', regex=True).astype(float)
|
Python convert multi-column pandas dataframe to single value table dataframe
Date : March 29 2020, 07:55 AM
it helps some times I am looking to convert the following multi-level column pandas dataframe to single value table. , Like @Wen stated use melt: df.rename_axis('Index').reset_index().melt('Index', value_name='Score')
Index Name Paper Score
0 2018-01-01 m 1 13
1 2018-06-01 m 1 11
2 2018-01-01 m 2 33
3 2018-06-01 m 2 43
4 2018-01-01 m 3 15
5 2018-06-01 m 3 30
6 2018-01-01 r 1 31
7 2018-06-01 r 1 36
8 2018-01-01 r 2 25
9 2018-06-01 r 2 23
10 2018-01-01 r 3 33
11 2018-06-01 r 3 37
|
Pandas Dataframe - Mysql select from table where condition in <A column from Dataframe>
Date : March 29 2020, 07:55 AM
|