Python Forum

Full Version: Extracting data without showing dtype, name etc.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a basic question and would be happy if someone could help me out.

I've extracted the prices of 2 stocks (Varta and Softcat) from a website using the following code:

import pandas as pd
# Get data from website
url = 'https://www.ariva.de/varta-aktie/kurs'
df = pd.read_html(url)
# Select table
df_Varta = df[3]
url = 'https://www.ariva.de/softcat-aktie/kurs'
df = pd.read_html(url)
df_Softcat = df[3]
# Extract price from column/ row 
price_Varta= df_Varta['Letzter'][df_Varta['Handelsplatz']=='Xetra']
price_Softcat= df_Softcat['Letzter'][df_Softcat['Handelsplatz']=='L&S RT']

print(price_Varta)
print(price_Softcat)
The code generates the following output:

Output:
5 126,90 € Name: Letzter, dtype: object 0 16,825 € Name: Letzter, dtype: object
However, I only want to know the price (without row numbers, name or dtype). Has anyone an idea how to achieve this result?

Many thanks in advance!

Best,

Tim
you need to add also .item()

price_Varta= df_Varta['Letzter'][df_Varta['Handelsplatz']=='Xetra'].item()
Hi Buran,

great, many thanks for this - now it works perfectly!
I am really not sure why you need specific item from the detaframe. Normally you would use pandas/dataframe for vectorized calculations.