我有一个由数百列组成的数据框,我也需要查看所有列名称.
我做了什么:
In[37]:
data_all2.columns
Run Code Online (Sandbox Code Playgroud)
输出是:
Out[37]:
Index(['customer_id', 'incoming', 'outgoing', 'awan', 'bank', 'family', 'food',
'government', 'internet', 'isipulsa',
...
'overdue_3months_feature78', 'overdue_3months_feature79',
'overdue_3months_feature80', 'overdue_3months_feature81',
'overdue_3months_feature82', 'overdue_3months_feature83',
'overdue_3months_feature84', 'overdue_3months_feature85',
'overdue_3months_feature86', 'loan_overdue_3months_total_y'],
dtype='object', length=102)
Run Code Online (Sandbox Code Playgroud)
如何显示所有列,而不是截断列表?
我想旋转一个 spark 数据框,我参考 pyspark 文档,并根据pivot功能,线索是.groupBy('name').pivot('name', values=None). 这是我的数据集,
In[75]: spDF.show()
Out[75]:
+-----------+-----------+
|customer_id| name|
+-----------+-----------+
| 25620| MCDonnalds|
| 25620| STARBUCKS|
| 25620| nan|
| 25620| nan|
| 25620| MCDonnalds|
| 25620| nan|
| 25620| MCDonnalds|
| 25620|DUNKINDONUT|
| 25620| LOTTERIA|
| 25620| nan|
| 25620| MCDonnalds|
| 25620|DUNKINDONUT|
| 25620|DUNKINDONUT|
| 25620| nan|
| 25620| nan|
| 25620| nan|
| 25620| nan|
| 25620| LOTTERIA|
| 25620| LOTTERIA|
| 25620| STARBUCKS|
+-----------+-----------+
only …Run Code Online (Sandbox Code Playgroud) 我如何根据数字的前几个数字切割字符串
这是我的资料
Id actual_pattern
1 100101
2 10101
3 1010101
4 101
Run Code Online (Sandbox Code Playgroud)
这是预期的输出
for cut_pattern1是from的前4位数字actual_pattern
,cut_pattern2是from的余数形式 cut_pattern1,如果from的余 cut_pattern1数不存在,则使cut_pattern2= 0
如果1in cut_pattern2,则make binary_cut2= 1,否则make binary_cut2= 0
Id actual_pattern cut_pattern1 cut_pattern2 binary_cut2
1 100101 1001 01 1
2 10101 1010 1 1
3 1010101 1010 101 1
4 101 101 0 0
Run Code Online (Sandbox Code Playgroud) 我想删除重复项并保留最后一个时间戳.想要删除的重复项是customer_id和.这var_name是我的数据
customer_id value var_name timestamp
1 1 apple 2018-03-22 00:00:00.000
2 3 apple 2018-03-23 08:00:00.000
2 4 apple 2018-03-24 08:00:00.000
1 1 orange 2018-03-22 08:00:00.000
2 3 orange 2018-03-24 08:00:00.000
2 5 orange 2018-03-23 08:00:00.000
Run Code Online (Sandbox Code Playgroud)
结果将是
customer_id value var_name timestamp
1 1 apple 2018-03-22 00:00:00.000
2 4 apple 2018-03-24 08:00:00.000
1 1 orange 2018-03-22 08:00:00.000
2 3 orange 2018-03-24 08:00:00.000
Run Code Online (Sandbox Code Playgroud) 我有数据集,数据集有配对重复。这是我的数据
Id antecedent descendant
1 one two
2 two one
3 two three
4 one three
5 three two
Run Code Online (Sandbox Code Playgroud)
这是我需要的,因为one, two等于two, one所以我想删除重复的对
Id antecedent descendant
1 one two
3 two three
4 one three
Run Code Online (Sandbox Code Playgroud) 这是我的数据
No Body
1 DaTa Analytics 2
2 StackOver 67
Run Code Online (Sandbox Code Playgroud)
这是我的预期输出
No Body Uppercase Lowercase
1 DaTa Analytics 2 3 10
2 StackOver 67 2 7
Run Code Online (Sandbox Code Playgroud) 这是我的数据
No Body
1 DaTa, Analytics 2
2 StackOver. 67%
Run Code Online (Sandbox Code Playgroud)
这是我的预期输出
No Body Non Alphanumeric
1 DaTa, Analytics 2 1
2 StackOver. 67% 2
Run Code Online (Sandbox Code Playgroud)
我只计算非字母数字,如! @ # & ( ) % – [ { } ] : ; ', ? / * 空格,数字不计算
我在分析 vincenty 距离时遇到问题,因为格式是object并且km在那里有指标,我想进一步分析。我想将 vincenty 距离转换为float格式
这是数据
customer_id lat_free long_free lat_device long_device radius timestamp
7509 -6.283468 106.857636 -7.802388 110.368660 1264.000000 2017-12-14 21:18:40.327
7509 -6.283468 106.857636 -7.804296 110.367192 14.000000 2017-12-15 20:02:21.923
Run Code Online (Sandbox Code Playgroud)
这是我的代码
from geopy.distance import vincenty
df['Vincenty_distance'] = df.apply(lambda x: vincenty((x['lat_free'], x['long_free']), (x['lat_device'], x['long_device'])), axis = 1)
Run Code Online (Sandbox Code Playgroud)
这是结果
customer_id lat_free long_free lat_device long_device radius timestamp Vincenty_distance
7509 -6.283468 106.857636 -7.802388 110.368660 1264.000000 2017-12-14 21:18:40.327 422.7123873310482 km
7509 -6.283468 106.857636 -7.804296 110.367192 14.000000 2017-12-15 20:02:21.923 422.64674499172787 km …Run Code Online (Sandbox Code Playgroud) 这是我的数据
Customer_id Date-of-birth
1 1992-07-02
2 1991-07-03
Run Code Online (Sandbox Code Playgroud)
这是我的代码
import datetime as dt
df['now'] = dt.datetime.now()
df['age'] = df['now'].dt.date - df['Date-of-birth']
Run Code Online (Sandbox Code Playgroud)
这是结果
Customer_id Date-of-birth age
1 1992-07-02 xxxx days
2 1991-07-03 xxxx days
Run Code Online (Sandbox Code Playgroud)
我想要的结果是
Customer_id Date-of-birth age
1 1992-07-02 26 years 22 days
2 1991-07-03 27 years 21 days
Run Code Online (Sandbox Code Playgroud)
只是让你现在,通过df.dtypes,Date-of-birth是一个对象,因为是基于下拉客户输入
我怎样才能做到这一点?我希望这个问题足够清楚
这是我的数据集
id keyword
1 transfer atm transfer atm
2 transfer transfer atm
3 atm transfer hospital
Run Code Online (Sandbox Code Playgroud)
这是我想要的是那种关键字按字母顺序,使这个独特的,基于字母在单词keyword按字母顺序排序后的是atm,hospital和transfer
id keyword
1 atm transfer
2 atm transfer
3 atm hospital transfer
Run Code Online (Sandbox Code Playgroud)