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
  Returning Column and Row Data From Spreadsheet knight2000 0 412 Oct-22-2023, 07:07 AM
Last Post: knight2000
  Using pyodbc&pandas to load a Table data to df tester_V 3 746 Sep-09-2023, 08:55 PM
Last Post: tester_V
  Find a string from a column of one table in another table visedwings049 8 1,084 Sep-07-2023, 03:22 PM
Last Post: deanhystad
  Color a table cell based on specific text Creepy 11 1,824 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Database that can compress a column, or all data, automatically? Calab 3 1,120 May-22-2023, 03:25 AM
Last Post: Calab
  Code for pullng all data in a column EmBeck87 5 1,050 Apr-03-2023, 03:43 PM
Last Post: deanhystad
  Grouping Data based on 30% bracket purnima1 4 1,142 Mar-10-2023, 07:38 PM
Last Post: deanhystad
  create new column based on condition arvin 12 2,130 Dec-13-2022, 04:53 PM
Last Post: jefsummers
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 797 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  conditionals based on data frame mbrown009 1 873 Aug-12-2022, 08:18 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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