pandas DataFrames Basic

Pandas is a high-level data manipulation tool developed by Wes McKinney. It is built on the Numpy package and its key data structure is called the DataFrame. DataFrames allow you to store and manipulate tabular data in rows of observations and columns of variables.

There are several ways to create a DataFrame. One way way is to use a dictionary. For example:

dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"],
       "capital": ["Brasilia", "Moscow", "New Dehli", "Beijing", "Pretoria"],
       "area": [8.516, 17.10, 3.286, 9.597, 1.221],
       "population": [200.4, 143.5, 1252, 1357, 52.98] }

import pandas as pd
print(dict)
brics = pd.DataFrame(dict)
print(brics)
brics.index = ["BR", "RU", "IN", "CH", "SA"]
print(brics)
  
===== RESTART: C:/python/PandasDataFrames01.py ==
{'country': ['Brazil', 'Russia', 'India', 'China', 'South Africa'], 
'capital': ['Brasilia', 'Moscow', 'New Dehli', 'Beijing', 'Pretoria'], 
'area': [8.516, 17.1, 3.286, 9.597, 1.221], 
'population': [200.4, 143.5, 1252, 1357, 52.98]}

        country    capital    area  population
0        Brazil   Brasilia   8.516      200.40
1        Russia     Moscow  17.100      143.50
2         India  New Dehli   3.286     1252.00
3         China    Beijing   9.597     1357.00
4  South Africa   Pretoria   1.221       52.98

         country    capital    area  population
BR        Brazil   Brasilia   8.516      200.40
RU        Russia     Moscow  17.100      143.50
IN         India  New Dehli   3.286     1252.00
CH         China    Beijing   9.597     1357.00
SA  South Africa   Pretoria   1.221       52.98
>>> 
source from here

コメント

このブログの人気の投稿

シェルピンスキーの三角形

global 変数・ローカル変数