Python Forum
Data extraction from a table based on column and row names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data extraction from a table based on column and row names
#1
Hello,

I have a basic question regarding the extraction of data from a table. Google did not bring up the desired result, so I would be happy if someone could help me further.

I use the following code to extract stock price data of Ford Motor Company from a website:

import pandas as pd
 
url = 'https://www.ariva.de/ford_motor-aktie/kurs'
df = pd.read_html(url)
df = df[3]
df
Output:
Handelsplatz Letzter Unnamed: 2 Änderung Änderung.1 Vortag letzte Stk. Tag-Stk. Kursspanne Zeit Unnamed: 10 Unnamed: 11 0 Tradegate 7,34 € NaN -0,57% NaN 7,382 € 400 15.279 7,27 - 7,489 08.01.21 NaN Hist. Kurse 1 Gettex 7,343 € NaN -0,20% NaN 7,358 € 0 166 7,308 - 7,459 08.01.21 NaN Hist. Kurse 2 L&S RT 7,362 € NaN 0 % NaN 7,362 € 0 0 7,362 - 7,362 12:35:15 NaN Hist. Kurse 3 HypoVereinsbank 8,995 $ NaN -0,66% NaN 9,055 $ 0 0 8,89 - 9,14 08.01.21 NaN Hist. Kurse 4 Quotrix 7,443 € NaN +1,50% NaN 7,333 € 0 0 7,443 - 7,443 08.01.21 NaN Hist. Kurse 5 NYSE 9,00 $ NaN -0,66% NaN 9,06 $ 1.954.291 12.467.481 8,89 - 9,14 08.01.21 NaN Hist. Kurse
Now I would like to know the NYSE price (i.e. row element: 'NYSE', column element: 'Letzter'). However, the order of the rows can sometimes change, so I can't directly say 'I need the price ('Letzter') from row 5'. Instead, I'd like to set it up so that it extracts the NYSE price regardless of which row has NYSE in it (NYSE will only appear once).

I would be grateful for any help!

Many thanks in advance.

Tim
Reply
#2
print(df['Letzter'][df['Handelsplatz']=='NYSE'])
# or
print(df.query('Handelsplatz=="NYSE"')['Letzter'])
tgottsc1 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 598 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  Extracting unique pairs from a data set based on another value rybina 2 205 Feb-12-2021, 08:36 AM
Last Post: rybina
  How to filter out Column data From Multiple rows data? firaki12345 10 474 Feb-06-2021, 04:54 AM
Last Post: buran
  Copying column values up based on other column values codelines 1 173 Jan-03-2021, 05:55 PM
Last Post: codelines
  update column in one data frame with value of column from another data frame flexer 0 173 Dec-04-2020, 03:29 PM
Last Post: flexer
  Load data from One oracle Table to Multiple tables amy83 1 208 Dec-02-2020, 01:57 AM
Last Post: Larz60+
  How to generate rows based on values in a column to fill missing values codesmatter 1 297 Oct-31-2020, 12:05 AM
Last Post: Larz60+
  I try to import data from Excel table to Word Template. NewbiePyPy 0 299 Oct-21-2020, 12:25 PM
Last Post: NewbiePyPy
  Pandas, Assign a value in a row, to another column based on a condition klllmmm 6 733 Oct-16-2020, 04:43 PM
Last Post: klllmmm
  How to merge three DataFrames based on specific column Mekala 0 331 Sep-08-2020, 02:01 PM
Last Post: Mekala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020