How to create dataframes and mess with elements in pandas

Why make a textual data frame

You may want to temporarily create a suitable data frame to play with pandas.

Try to make

#Import pandas
import pandas as pd

#Create a dataframe using range
df = pd.DataFrame({"col_name":range(4)})
print(df)
"""
    col_name
0          0
1          1
2          2
3          3
"""

Try to play with

Try changing the name of the index and columns of the data frame you just created Further tweak the elements of the data frame

df.index = ["zero","one","two","three"]
df.columns = ["column"]
df.loc["one", "column"] = 7
print(df)
"""
       column
zero        0
one         7
two         2
three       3
"""

Other ways to play

#Make 5 or more elements of df NaN
df = df[df<5]
print(df)
"""
       column
zero        0
one       NaN
two         2
three       3
"""

#NaN yeah!Fill
df = df.fillna("yeah!")
print(df)
"""
       column
zero        0
one     yeah!
two         2
three       3
"""

Recommended Posts

How to create dataframes and mess with elements in pandas
How to access with cache when reading_json in pandas
How to extract null values and non-null values with pandas
How to write soberly in pandas
How to swap elements in an array in Python, and how to reverse an array.
How to create and use static / dynamic libraries in C
Dynamically create new dataframes with pandas
Data science companion in python, how to specify elements in pandas
How to log in to AtCoder with Python and submit automatically
How to compare lists and retrieve common elements in a list
How to create a heatmap with an arbitrary domain in Python
How to work with BigQuery in Python
How to reassign index in pandas dataframe
How to read CSV files in Pandas
How to use is and == in Python
How to use pandas Timestamp and date_range
How to get a specific column name and index name in pandas DataFrame
How to get the date and time difference in seconds with python
How to deal with memory leaks in matplotlib.pyplot
How to create sample CSV data with hypothesis
[REAPER] How to play with Reascript in Python
How to generate permutations in Python and C ++
How to create explanatory variables and objective functions
How to create a JSON file in Python
[Python] How to read excel file with pandas
How to deal with run-time errors in subprocess.call
How to create data to put in CNN (Chainer)
How to use tkinter with python in pyenv
How to create a multi-platform app with kivy
[Python] How to create a dictionary type list, add / change / delete elements, and extract with a for statement
How to create a Rest Api in Django
Add totals to rows and columns in pandas
How to plot autocorrelation and partial autocorrelation in python
How to create random numbers with NumPy's random module
How to remove duplicate elements in Python3 list
How to count the number of elements in Django and output to a template
The first step to log analysis (how to format and put log data in Pandas)
[Pandas] How to check duplicates and delete duplicates in a table (equivalent to deleting duplicates in Excel)
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
How to use Pandas 2
Convert 202003 to 2020-03 with pandas
(Diary 1) How to create, reference, and register data in the SQL database of Microsoft Azure service with python
How to convert / restore a string with [] in python
How to do hash calculation with salt in Python
How to define Decorator and Decomaker in one function
Explain in detail how to make sounds with python
How to create a submenu with the [Blender] plugin
Create Amazon Linux with AWS EC2 and log in
How to convert horizontally held data to vertically held data with pandas
How to deal with pyenv initialization failure in fish 3.1.0
How to run tests in bulk with Python unittest
How to load files in Google Drive with Google Colaboratory
How to share folders with Docker and Windows with tensorflow
How to extract non-missing value nan data with pandas
How to output CSV of multi-line header with pandas
How to convert JSON file to CSV file with Python Pandas
[Python] How to deal with pandas read_html read error
[Python] How to sort dict in list and instance in list
How to create an image uploader in Bottle (Python)
I tried to summarize how to use pandas in python
How to use Decorator in Django and how to make it