简体   繁体   English

根据文件名生成熊猫列值

[英]Generating pandas column values based upon filename

I wish to populate three columns (day, week, year) in a pandas data frame.我希望在 Pandas 数据框中填充三列(日、周、年)。

The data is to be extracted from a filename which are in this format:数据将从以下格式的文件名中提取:

AAAA_DDWWYYYY.txt

where:在哪里:

  • AAAA = alpha characters AAAA = 字母字符
  • DD = Day DD = 天
  • WW = Month WW = 月
  • YYYY = Year YYYY = 年

For example:例如:

NDVI_01012016.txt

is:是:

  • Day = 01天 = 01
  • Week = 01周 = 01
  • Year = 2016年 = 2016

Assuming df is your dataframe::假设df是你的数据帧::

df.ix[df.filename == 'NDVI_01012016.txt', 'Day'] = 1
df.ix[df.filename == 'NDVI_01012016.txt', 'Week'] = '01'
df.ix[df.filename == 'NDVI_01012016.txt', 'Year'] = '2016'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据 Pandas 中的条件删除列中的值 - Deleting values in the column based upon condition in Pandas 根据pandas中另一列的值生成一列(python) - generating a column based on the values in another column in pandas (python) 根据一列中的特定值在 pandas dataframe 中查找时间增量 - Finding a timedelta in pandas dataframe based upon specific values in one column 包含对象列表的pandas列,根据键名拆分此列,并将值存储为逗号分隔的值 - pandas column containing list of objects, split this column based upon keynames and store values as comma separated values 返回根据不同列中的总唯一值排序的 pandas 列 - Returning a pandas column sorted based upon the total unique values in a different column Pandas 在聚合时根据列中的最大值滚动列值 - Pandas rolling up column values based upon max value in column when aggregating 根据 Pandas 中不同列的 group by 更新特定列值 - Update specific column values based upon group by from different column in Pandas Pandas 根据同一数据框中另一列的条件替换列值 - Pandas Replace column values based on condition upon another column in the same data frame 基于2系列和列表生成Pandas列 - Generating Pandas Column Based on 2 Series and List 我想根据 pandas 列发送 email - I want to send email based upon a pandas column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM