Electron microscopy
 
PythonML
Creating, Selecting, Filtering and Aggregating Data, Running SQL Queries
- Python Automation and Machine Learning for ICs -
- An Online Book: Python Automation and Machine Learning for ICs by Yougui Liao -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

Basic data operation in DataFrame

  • Creating Data

    import pandas as pd

      data = {'Name': ['John', 'Anna', 'James', 'Linda'],
      'Age': [28, 22, 35, 32],
      'City': ['New York', 'Paris', 'London', 'Berlin']}
      df = pd.DataFrame(data)

  • Selecting Data

      # Selecting the 'Name' and 'Age' columns
      selected_data = df[['Name', 'Age']]

  • Filtering Data

      # Filtering to find people older than 30
      older_than_30 = df[df['Age'] > 30]

  • Aggregating Data

      # Average age of people in each city
      average_age = df.groupby('City')['Age'].mean()

  • Running SQL Queries

    Pandas does not support SQL natively but can use the pandasql library:

      import pandasql as ps
      query = "SELECT * FROM df WHERE Age > 30"
      result = ps.sqldf(query, locals())

 

==========================================

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================