我有一个百万行时间序列数据,其中日期列中的一些值混淆了日期/月的值。
我如何在不破坏那些正确的东西的情况下,有效地解决这些问题?
# this creates a dataframe with muddled dates
import pandas as pd
import numpy as np
from pandas import Timestamp
start = Timestamp(2013,1,1)
dates = pd.date_range(start, periods=942)[::-1]
muddler = {}
for d in dates:
if d.day
我想检查pandas.DataFrame列是否包含特定值。例如,这个玩具Dataframe在"two"列中有一个"h"
import pandas as pd
df = pd.DataFrame(
np.array(list("abcdefghi")).reshape((3, 3)),
columns=["one", "two", "three"]
)
df
one two three
0 a b c
1 d e f
2 g h i
我的问题是泛型。好吧,再试一次。我想要一个在第一列a中包含每月日期的数据。THen,我想遍历这些日期并填充第b行和第c行中的值。
import pandas as pd
from pandas import *
import datetime as dt
#try to generate a dataframe with dates
#This ist the dataframe, but how can I fill the dates
dfa = pd.DataFrame(columns=['date', '1G', '10G'])
p
如果文本列相同,我希望将日期列中的所有日期更改为最早日期。
import pandas as pd
df = pd.DataFrame({'text': ['I like python pandas',
'find all function input from help jupyter',
'function input',
'func
我从API中获取数据,并将其放入Pandas DataFrame中。日期列需要格式化为日期/时间,我正在这样做。但是,API有时会返回没有毫秒的日期,这与格式模式不匹配。这将导致一个错误:
time data '2020-07-30T15:57:37Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ' (match)
在本例中,如何将date列格式化为date/time,从而将所有日期格式化为毫秒?
import pandas as pd
dates = {
'date': ['202
我有一个Pandas DataFrame,列如下:
UserID, Date, (other columns that we can ignore here)
我试图只选择访问多个日期的用户。我目前使用的是groupby(['UserID', 'Date'])和一个for循环,在这个循环中,我只删除用户一个结果,但我觉得有更好的方法可以做到这一点。
谢谢
我使用for循环读取pandas dataframe中的列,并使用嵌套的if语句查找日期时间范围内的最小值和最大值。
我可以确定所需的datetime列,但找不到将column变量传递给dataframe.series.min()和max语句的正确方法。
import pandas as pd
data = pd.somedata()
for column in data.columns:
if data[column].dtype == 'datetime64[ns]':
data.column.min()
data.colum
首先我会说我不是最有经验的Python,我还在学习。对于我正在处理的当前项目,我必须将CSV文件加载到Python中,在Python中我创建了一个熊猫DataFrame。目标是返回每列的数据类型,特别是具有不同日期格式的数据类型。我创建了一个小的示例CSV文件来测试它是否可以识别正确的数据类型。
import pandas as pd
import numpy as np
from tabulate import tabulate
from datetime import datetime
#Read the CSV file into Pandas
要将多个变量传递给一个普通的python函数,您只需编写如下代码:
def a_function(date,string,float):
do something....
convert string to int,
date = date + (float * int) days
return date
在使用Pandas DataFrames时,我知道您可以基于一个列的内容创建一个新列,如下所示:
df['new_col']) = df['column_A'].map(a_function)
# This m
我对pandas和数据帧还很陌生,我需要在我的数据帧中添加一个新的列,这就像是在算术运算的基础上组合其他列。
Dataframe columns:
col1 , col2 col3.. etc
Functions:
sum()
count()
distinct()
min()
etc..
Operators: like + - * / etc..
now user can drag and drop anything from above 3(functions, columns
and operators) which might make expression like..
s