怎么做像知乎一样的网站,网站建设 php 企业网站,外包网站多少钱,重庆市证书查询入口Pandas DataFrame是带有标签轴(行和列)的二维大小可变的#xff0c;可能是异构的表格数据结构。算术运算在行和列标签上对齐。可以将其视为Series对象的dict-like容器。这是 Pandas 的主要数据结构。Pandas DataFrame.tz_convert()用于将tz-aware轴转换为目标时区。用法#…Pandas DataFrame是带有标签轴(行和列)的二维大小可变的可能是异构的表格数据结构。算术运算在行和列标签上对齐。可以将其视为Series对象的dict-like容器。这是 Pandas 的主要数据结构。Pandas DataFrame.tz_convert()用于将tz-aware轴转换为目标时区。用法 DataFrame.tz_convert(tz, axis0, levelNone, copyTrue)参数tz:字符串或pytz.timezone对象axis:转换轴level:如果轴为MultiIndex则转换特定级别。否则必须为Nonecopy:同时复制基础数据返回tz转换的数据帧范例1采用DataFrame.tz_convert()函数转换给定数据帧的时区。# importing pandas as pdimport pandas as pd# Creating the DataFramedf pd.DataFrame({Weight:[45, 88, 56, 15, 71],Name:[Sam, Andrea, Alex, Robin, Kia],Age:[14, 25, 55, 8, 21]})# Create the indexindex_ pd.date_range(2010-10-09 08:45, periods 5, freq H, tz US / Central)# Set the indexdf.index index_# Print the DataFrameprint(df)输出现在我们将使用DataFrame.tz_convert()函数将给定 DataFrame 的时区转换为“欧洲/柏林”。# Lets find out the current timezone# of the given dataframeprint(df.index)# Lets convert the timezone of the# dataframe to Europe / Berlindf df.tz_convert(tz Europe / Berlin)# Lets find out the current timezone# of the given dataframeprint(df.index)输出正如我们在输出中看到的DataFrame.tz_convert()函数已成功将给定数据帧的时区转换为所需的时区。范例2采用DataFrame.tz_convert()函数转换给定数据帧的时区。给定数据帧的索引是一个MultiIndex。# importing pandas as pdimport pandas as pd# Creating the DataFramedf pd.DataFrame({Weight:[45, 88, 56, 15, 71],Name:[Sam, Andrea, Alex, Robin, Kia],Age:[14, 25, 55, 8, 21]})# Create the MultiIndexindex_ pd.MultiIndex.from_product([[Date], pd.date_range(2010-10-09 08:45, periods 5, freq H, tz US/Central)], names [Level 1, Level 2])# Set the indexdf.index index_# Print the DataFrameprint(df)输出现在我们将使用DataFrame.tz_convert()函数可将给定 DataFrame 中的MultiIndex级别1的时区转换为“欧洲/柏林”。# Lets find out the current timezone# of the Level 1 of the given dataframeprint(df.index[1])# Lets convert the timezone of the# level 1 of the dataframe to Europe / Berlindf df.tz_convert(tz Europe/Berlin, level 1)# Lets find out the current timezone# of the level 1 of the given dataframeprint(df.index[1])输出正如我们在输出中看到的DataFrame.tz_convert()函数已成功将给定数据帧中所需级别的时区转换为所需时区。