current position:Home>[Python kaggle] pandas basic exercises in machine learning series (6)
[Python kaggle] pandas basic exercises in machine learning series (6)
2021-08-23 10:18:58 【Haibang Pro】
Preface
Hello! buddy !
Thank you very much for reading Haihong's article , If there are mistakes in the text , You are welcome to point out ~
Self introduction. ଘ(੭ˊᵕˋ)੭
nickname : Sea boom
label : Program the ape |C++ player | Student
brief introduction : because C Language and programming , Then I turned to computer science , I was lucky to win some national awards 、 Provincial award … It has been insured . Currently learning C++/Linux/Python
Learning experience : Solid foundation + Take more notes + Knock more code + Think more + Learn English well !
Beginners Python Xiaobai stage
The article is only for your own study notes For knowledge system establishment and review
There are not many questions Learn a question Understand a problem
Know what it is Know why !
Previous recommendation
【Python|Kaggle】 Machine learning series Pandas Basic exercises ( One )
【Python|Kaggle】 Machine learning series Pandas Basic exercises ( Two )
【Python|Kaggle】 Machine learning series Pandas Basic exercises ( 3、 ... and )
【Python|Kaggle】 Machine learning series Pandas Basic exercises ( Four )
【Python|Kaggle】 Machine learning series Pandas Basic exercises ( 5、 ... and )
Introduction
Run the following cell to load your data and some utility functions.
Run the following code Import the library needed for the exercise 、 Data sets …
import pandas as pd
reviews = pd.read_csv("../input/wine-reviews/winemag-data-130k-v2.csv", index_col=0)
from learntools.core import binder; binder.bind(globals())
from learntools.pandas.renaming_and_combining import *
print("Setup complete.")
Exercises
View the first several lines of your data by running the cell below:
reviews.head()
Data used :
1.
subject
region_1
and region_2
are pretty uninformative names for locale columns in the dataset. Create a copy of reviews
with these columns renamed to region
and locale
, respectively.
answer
The title mean :
modify
region_1
、region_2
As aregion
、locale
In fact, it is to modify the following names
renamed = reviews.rename(columns={
'region_1':'region','region_2':'locale'})
Running results :
Other references Demo:
renamed = reviews.rename(columns=dict(region_1='region', region_2='locale'))
2.
subject
Set the index name in the dataset to wines
.
answer
The title mean :
Name the index axis wines
reindexed = reviews.rename_axis('wines', axis='rows')
Running results :
3.
subject
The Things on Reddit dataset includes product links from a selection of top-ranked forums (“subreddits”) on reddit.com. Run the cell below to load a dataframe of products mentioned on the /r/gaming subreddit and another dataframe for products mentioned on the r//movies subreddit.
Run the following code Import the two data sets required for this question
gaming_products = pd.read_csv("../input/things-on-reddit/top-things/top-things/reddits/g/gaming.csv")
gaming_products['subreddit'] = "r/gaming"
movie_products = pd.read_csv("../input/things-on-reddit/top-things/top-things/reddits/m/movies.csv")
movie_products['subreddit'] = "r/movies"
gaming_products
Create a DataFrame of products mentioned on either subreddit.
answer
The title mean :
Merge two datasets
combined_products = pd.concat([gaming_products, movie_products])
Running results :
4.
subject
The Powerlifting Database dataset on Kaggle includes one CSV table for powerlifting meets and a separate one for powerlifting competitors. Run the cell below to load these datasets into dataframes:
Run the following code Import the data set required for this question
powerlifting_meets = pd.read_csv("../input/powerlifting-database/meets.csv")
powerlifting_competitors = pd.read_csv("../input/powerlifting-database/openpowerlifting.csv")
powerlifting_meets,powerlifting_competitors
The first data set is as follows ( Observe the number of columns )
The second data set is as follows ( Observe the number of columns )
Both tables include references to a MeetID, a unique key for each meet (competition) included in the database. Using this, generate a dataset combining the two tables into one.
answer
The title mean :
basis MeetID For two data sets To merge horizontally
powerlifting_combined = powerlifting_meets.set_index("MeetID").join(powerlifting_competitors.set_index("MeetID"))
Running results :
Conclusion
The article is only for study notes , Record from 0 To 1 A process of
I hope it will be of some help to you , If you have any mistakes, you are welcome to correct them ~
I am a Sea boom ଘ(੭ˊᵕˋ)੭
If you think it's ok , Please like it
Thank you for your support ️
copyright notice
author[Haibang Pro],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2021/08/20210823101855477j.html
The sidebar is recommended
- [Python introduction project] use Python to generate QR code
- Compile D + +, and use d to call C from python
- Quickly build Django blog based on function calculation
- Python collects and monitors system data -- psutil
- Finally, this Python import guide has been sorted out. Look!
- Quickly build Django blog based on function calculation
- Python interface test unittest usage details
- Implementation of top-level design pattern in Python
- You can easily get started with Excel. Python data analysis package pandas (VII): breakdown
- Python simulation random coin toss (non optimized version)
guess what you like
-
Python tiktok 5000+ V, and found that everyone love this video.
-
Using linear systems in python with scipy.linalg
-
Using linear systems in python with scipy.linalg
-
Together with Python to do a license plate automatic recognition system, fun and practical!
-
You can easily get started with Excel. Python data analysis package pandas (XI): segment matching
-
Advanced practical case: Javascript confusion of Python anti crawling
-
Using linear systems in python with scipy.linalg
-
Fast power modulus Python implementation of large numbers
-
Quickly build Django blog based on function calculation
-
This paper clarifies the chaotic switching operation and elegant derivation of Python
Random recommended
- You can easily get started with Excel pandas (I): filtering function
- You can easily get started with Excel. Python data analysis package pandas (II): advanced filtering (I)
- You can easily get started with Excel. Python data analysis package pandas (2): advanced filtering (2)
- You can easily get started with Excel. Python data analysis package pandas (3): making score bar
- Test Development: self study Dubbo + Python experience summary and sharing
- You can easily get started with Excel. Python data analysis package pandas (V): duplicate value processing
- How does Python correctly call jar package encryption to get the encrypted value?
- Python 3 interview question: give an array. If there is 0 in the array, add a 0 after 0, and the overall array length remains the same
- Python simple Snake game (single player mode)
- Using linear systems in python with scipy.linalg
- Python executes functions and even code through strings! Come and understand the operation of such a top!
- Decoding the verification code of Taobao slider with Python + selenium, the road of information security
- [Python introduction project] use Python to generate QR code
- Vanessa basks in her photos and gets caught up in the golden python. There are highlights in the accompanying text. She can't forget Kobe after all
- [windows] Python installation pyteseract
- [introduction to Python project] create bar chart animation in Python
- Fundamentals of Python I
- Python series tutorials 116
- Python code reading (chapter 35): fully (deeply) expand nested lists
- Practical series 1 ️⃣ Wechat applet automatic testing practice (with Python source code)
- Python Basics: do you know how to use lists?
- Solution of no Python 3.9 installation was detected when uninstalling Python
- [Python homework] coupling network information dissemination
- [common links of Python & Python]
- Python application software development tool - tkinterdesigner v1.0 5.1 release!
- [Python development tool tkinterdiesigner]: example: develop stock monitoring alarm using Tkinter desinger
- [Python development tool Tkinter designer]: Lecture 2: introduction to Tkinter designer's example project
- [Python development tool Tkinter designer]: Lecture 1: introduction to the basic functions of Tkinter Designer
- [introduction to Python tutorial] use Python 3 to teach you how to extract any HTML main content
- Python socket implements UDP server and client
- Python socket implements TCP server and client
- leetcode 1261. Find Elements in a Contaminated Binary Tree(python)
- [algorithm learning] 1486 Array XOR operation (Java / C / C + + / Python / go / trust)
- leetcode 1974. Minimum Time to Type Word Using Special Typewriter(python)
- The mobile phone uses Python to operate picture files
- [learning notes] Python exception handling try except...
- Two methods of using pandas to read poorly structured excel. You're welcome to take them away
- Python sum (): the summation method of Python
- Practical experience sharing: use pyo3 to build your Python module
- Using Python to realize multitasking process