简体   繁体   中英

How to extract numeric elements from an entire row in a dataframe, using python

Ex - Extract all numbers from the first row

can you give csv file of data frame and which numbers you want to extract?

here is one way for a similar data frame

 #code to extract no. from a dataframe
from numpy.core.arrayprint import printoptions
import pandas as pd
import numpy as np

dict={'0':['almarai investors  according to investor type loss','almarai investors  according to investor type loss',
'savola group','hh prince','governmenatla','other'],
'1':['31 dec2020','percent','34.5%','23.7%','56.5%','9.1%'],'2':[np.nan,np.nan,1,1,5,4125],
'font':['Normal','Normal','Normal','Normal','Normal','Normal']}

df= pd.DataFrame(dict)
 

df_numerics=df.select_dtypes(include=np.number)
print(df_numerics)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM