-2

I am editing a CSV file in Python, I have deleted some columns, created an index and filtered. But I have not been able to extract the numerical part of the columas. How can I extract only the numerical information from the columns?

Extract only the numeric part of the column data. example:

MarketTime = 11: 18: 26.549

The whole column should be like this:

11: 18: 26,549

import pandas as pd

df = pd.read_csv('C:/Users/TECNOLOGIA/datos.csv',names=['LocalTime', 'Message', 'MarketTime', 'Symbol', 'Type', 'Price', 'Size', 'Source','Condition','Tick','Mmid','SubMarketId','Date'], usecols=['Type','MarketTime','Price'],index_col='Type') df=(df.loc['Type=0']) print (df)

8
  • Possible duplicate of How do I find numeric columns in Pandas? Commented Jan 9, 2018 at 22:19
  • 2
    Please include the data in the question, not as some image that might disappear in the future. Commented Jan 9, 2018 at 22:21
  • 1
    we're not code writing service. Please also include what you tried and where you got stuck. Also, include the data array so that we can help you better Commented Jan 9, 2018 at 22:22
  • @Aiven: Nope, that isn't it. Commented Jan 9, 2018 at 22:23
  • 1
    Please add your data as text in your question. Pictures (or links of pictures) do not make it easy for us to answer the question. Commented Jan 9, 2018 at 22:32

1 Answer 1

0

Adapting the Regex/Pandas StringMethods answer given at pandas applying regex to replace values, you will have something like this:

import pandas as pd

df = pd.DataFrame(['MarketTime=11:18:28.792','MarketTime=11:18:28.792'], columns=['MarketTime'])

df['MarketTime'] = df['MarketTime'].str.extract(r'([\d:,.]+)')
print(df)
Sign up to request clarification or add additional context in comments.

3 Comments

And please clean up and format your original question, removing the image links.
Thanks Alex, I'm trying to work on all the values ​​in the column. Is it possible to apply it to the whole column?
Umm it IS applying the extraction to the whole column, what are you seeing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.