1??创建一个 DataFrame
import numpy as np
import pandas as pd
data = [{'a':1,'b':2},{'a':5,'b':10,'c':20}]
df = pd.DataFrame(data)
2??Pandas--如何修改 DataFrame 列名?
df.rename(columns={'a':'国家'}, inplace=True)
3??Pandas--如何对数据进行排序?
df.sort_values(by='国家', ascending=False, inplace=True)
4??Pandas--如何将列名的数字类型改为字符类型?
df.columns = map(str,df.columns)
5??Pandas--如何修改日期格式错误数据
data = {'data':['2020/12/01','2020/12/02','20201226'],"duration":[50,40,45]}
df = pd.DataFrame(data,index=["day1","day2","day3"])
df['data'] = pd.to_datetime(df['data'])
6??Pandas--如何删除重复数据
persons = {"name":['Google','Runoob','Runoob','Taobao'],"age":[50,40,40,23]}
df = pd.DataFrame(persons)
df.drop_duplicates(inplace=True)
?
|